Created
October 25, 2018 10:04
-
-
Save castaneai/445e8295af80c54b31225f5cd2292b44 to your computer and use it in GitHub Desktop.
io.TeeReader example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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