go-examples/go-cat2/main.go
2017-07-07 17:59:01 +02:00

26 lines
418 B
Go

package main
import "io"
import "log"
import "os"
var reader io.Reader
func main() {
if len(os.Args) <= 1 {
reader = os.Stdin
} else {
readers := []io.Reader{}
for _, fname := range os.Args[1:] {
if f, err := os.Open(fname); err != nil {
log.Fatalln(err)
} else {
defer f.Close()
readers = append(readers, f)
}
}
reader = io.MultiReader(readers...)
}
io.Copy(os.Stdout, reader)
}