When you need to write the same output into more than one target, there is a helping hand available in the built-in package. This recipe shows how to implement writing simultaneously into multiple targets.
Writing to multiple writers at once
How to do it...
- Open the console and create the folder chapter05/recipe08.
- Navigate to the directory.
- Create the multiwr.go file with the following content:
package main
import "io"
import "bytes"
import "os"
import "fmt"
func main() {
buf := bytes.NewBuffer([]byte{})
f, err := os.OpenFile("sample.txt", os.O_CREATE|os.O_RDWR,
os.ModePerm)
...