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.4k Golang : Get timezone offset from date or timestamp
+13.4k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+4.8k Adding Skype actions such as call and chat into web page examples
+20.1k Golang : How to get time from unix nano example
+9.6k Golang : Generate EAN barcode
+13.2k Golang : How to get a user home directory path?
+4.5k Golang : Valued expressions and functions example
+5.4k PHP : See installed compiled-in-modules
+26.8k Golang : Encrypt and decrypt data with AES crypto
+16.1k Golang : How to login and logout with JWT example
+9k Golang : Accept any number of function arguments with three dots(...)
+13.6k Golang : Get constant name from value