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
+41.4k Golang : Convert string to array/slice
+18.8k Golang : Delete duplicate items from a slice/array
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+8.7k Golang : How to join strings?
+5.9k Golang : Generate multiplication table from an integer example
+15k Golang : How do I get the local IP (non-loopback) address ?
+7.1k Golang : A simple forex opportunities scanner
+40.1k Golang : UDP client server read write example
+7.9k Golang : Get today's weekday name and calculate target day distance example
+20.7k Golang : Saving private and public key to files
+7.3k Golang : File system scanning
+13.6k Android Studio : Password input and reveal password example