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
+9.3k Golang : Web(Javascript) to server-side websocket example
+87.3k Golang : How to convert character to ASCII and back
+15.1k Golang : How to check if IP address is in range
+11.2k Golang : Byte format example
+7.4k Golang : Get YouTube playlist
+5.8k Golang : Launching your executable inside a console under Linux
+22.1k Golang : Repeat a character by multiple of x factor
+31k Golang : Calculate percentage change of two values
+41.4k Golang : Convert string to array/slice
+14.2k Golang : Get uploaded file name or access uploaded files
+22.5k Generate checksum for a file in Go
+29.5k Golang : Record voice(audio) from microphone to .WAV file