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
+9.5k Golang : Terminate-stay-resident or daemonize your program?
+11.8k Golang : Display a text file line by line with line number example
+13.7k Golang : Count number of runes in string
+16.6k Golang : Send email and SMTP configuration example
+10.7k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+12.9k Golang : Add ASCII art to command line application launching process
+24.8k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+12k Golang : Convert(cast) bigint to string
+9.7k Golang : Validate IPv6 example
+10.8k Golang : Allow Cross-Origin Resource Sharing request
+32.9k Golang : Regular Expression for alphanumeric and underscore
+26.8k Golang : How to check if a connection to database is still alive ?