shad-go/lectures/09-io/teereader/main.go
2020-04-23 04:40:13 +03:00

29 lines
372 B
Go

package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"strings"
)
func main() {
r := strings.NewReader("some io.Reader stream to be read\n")
var buf bytes.Buffer
tee := io.TeeReader(r, &buf)
printall := func(r io.Reader) {
b, err := ioutil.ReadAll(r)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", b)
}
printall(tee)
printall(&buf)
}