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
+18.9k Golang : Count number of digits from given integer value
+9.5k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+9.4k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+6.9k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+14.8k Golang : How to check if input from os.Args is integer?
+5k Golang : How to write backslash in string?
+26k Golang : Record voice(audio) from microphone to .WAV file
+5.1k Golang : Debug with Godebug
+20.4k Golang : Convert seconds to minutes and remainder seconds
+18.3k Golang : Archive directory with tar and gzip
+6.3k Golang : How to stop user from directly running an executable file?
+11.8k Golang : Qt progress dialog example