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
+17k Golang : Capture stdout of a child process and act according to the result
+24.5k Golang : GORM read from database example
+8.9k Golang : Sort lines of text example
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+5.4k Golang : What is StructTag and how to get StructTag's value?
+4.9k JQuery : Calling a function inside Jquery(document) block
+11.7k How to tell if a binary(executable) file or web application is built with Golang?
+4.7k Fix Google Analytics Redundant Hostnames problem
+10.2k Golang : Use regular expression to get all upper case or lower case characters example
+7.7k Golang : Generate human readable password
+9.4k Golang : Apply Histogram Equalization to color images
+7.5k Golang : How to stop user from directly running an executable file?