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
+15.7k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+22.2k Golang : Convert seconds to minutes and remainder seconds
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+6.1k Golang : Dealing with backquote
+6.8k Golang : Calculate pivot points for a cross
+6.1k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+8.1k Golang : Append and add item in slice
+51.9k Golang : How to get time in milliseconds?
+7.5k Golang : How to handle file size larger than available memory panic issue
+29.4k Golang : JQuery AJAX post data to server and send data back to client example
+19.2k Golang : Check whether a network interface is up on your machine