Skip to content

Instantly share code, notes, and snippets.

@eikaas
Created April 29, 2015 14:12
Show Gist options
  • Save eikaas/c236e1e04ef8dad23839 to your computer and use it in GitHub Desktop.
Save eikaas/c236e1e04ef8dad23839 to your computer and use it in GitHub Desktop.
package main
import "os"
import "io"
import "encoding/json"
type MyWriters struct {
StandardOutput io.Writer
StandardError io.Writer
FileOutput io.Writer
Everything io.Writer
}
func main() {
myFileWriter, err := os.Create("output.json")
defer myFileWriter.Close()
if err != nil {
os.Exit(1)
}
out := MyWriters{
StandardOutput: os.Stdout,
StandardError: os.Stderr,
FileOutput: myFileWriter,
}
out.Everything = io.MultiWriter(os.Stdout, os.Stderr, myFileWriter)
json.NewEncoder(out.Everything).Encode(struct {
Name string `json: "name"`
Age int `json: "age"`
}{
"Hasse Laugen",
30,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment