Golang strings.NewReader() function example
package strings
Golang strings.NewReader() function usage example
package main
import (
"fmt"
"strings"
)
func main() {
str := "HTTP/1.1 204 No Content\r\n\r\n"
reader := strings.NewReader(str)
l := reader.Len()
n, err := reader.Read([]byte("HTTP"))
if err != nil {
fmt.Println(err)
}
fmt.Println("Reader length is : ", l)
fmt.Println("Bytes read : ", n)
}
Output :
Reader length is : 27
Bytes read : 4
References :
http://golang.org/pkg/strings/#NewReader http://golang.org/pkg/strings/#Reader.Len http://golang.org/pkg/strings/#Reader.Read
Advertisement
Something interesting
Tutorials
+15.6k Golang : rune literal not terminated error
+12.4k Golang : Search and extract certain XML data example
+11.2k Golang : How to pipe input data to executing child process?
+23k Golang : simulate tail -f or read last line from log file example
+12.4k Elastic Search : Return all records (higher than default 10)
+5.6k Javascript : How to refresh page with JQuery ?
+9.5k Golang : Accessing content anonymously with Tor
+12.1k Golang : convert(cast) string to integer value
+5k Golang : Display packages names during compilation
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy