go-examples/go-cat2/main.go

26 lines
418 B
Go
Raw Normal View History

2017-07-07 12:46:40 +00:00
package main
import "io"
import "log"
import "os"
var reader io.Reader
func main() {
if len(os.Args) <= 1 {
2017-07-07 15:59:01 +00:00
reader = os.Stdin
2017-07-07 12:46:40 +00:00
} else {
readers := []io.Reader{}
2017-07-07 15:13:07 +00:00
for _, fname := range os.Args[1:] {
2017-07-07 15:59:01 +00:00
if f, err := os.Open(fname); err != nil {
log.Fatalln(err)
} else {
defer f.Close()
readers = append(readers, f)
}
2017-07-07 12:46:40 +00:00
}
reader = io.MultiReader(readers...)
}
2017-07-07 15:59:01 +00:00
io.Copy(os.Stdout, reader)
2017-07-07 12:46:40 +00:00
}