Skip to content

Instantly share code, notes, and snippets.

@castaneai
Created October 25, 2018 10:04
Show Gist options
  • Save castaneai/445e8295af80c54b31225f5cd2292b44 to your computer and use it in GitHub Desktop.
Save castaneai/445e8295af80c54b31225f5cd2292b44 to your computer and use it in GitHub Desktop.
io.TeeReader example
package main
import (
"os"
"io"
"log"
)
func main() {
filename := os.Args[1]
file, err := os.Create(filename)
if err != nil {
log.Fatalln(err)
}
defer file.Close()
tee := io.TeeReader(os.Stdin, file)
if _, err := io.Copy(os.Stdout, tee); err != nil {
log.Fatalln(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment