Golang io.MultiReader function example
package io
Golang io.MultiReader function usage example
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
)
func main() {
reader := bytes.NewReader([]byte("abcdefghijkl"))
reader2 := bytes.NewReader([]byte("mnopqrstuvwxyz"))
buff := []io.Reader{reader, reader2}
// FROM http://golang.org/pkg/io/#MultiReader
// MultiReader returns a Reader that's the logical concatenation
// of the provided input readers. They're read sequentially.
combined := io.MultiReader(buff...)
data, _ := ioutil.ReadAll(combined)
fmt.Println(string(data))
}
Output :
abcdefghijklmnopqrstuvwxyz
Reference :
Advertisement
Something interesting
Tutorials
+10.6k Golang : Get local time and equivalent time in different time zone
+11k Golang : Generate random elements without repetition or duplicate
+17.3k Golang : How to tell if a file is compressed either gzip or zip ?
+23.2k Golang : Print out struct values in string format
+9k Golang : Go as a script or running go with shebang/hashbang style
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+11.8k Golang : GTK Input dialog box examples
+6.4k PHP : Proper way to get UTF-8 character or string length
+8.1k Golang : Tell color name with OpenCV example
+5.6k Javascript : How to refresh page with JQuery ?
+19.5k Golang : How to Set or Add Header http.ResponseWriter?