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
+11.4k Golang : Verify Linux user password again before executing a program example
+17.4k Golang : How to log each HTTP request to your web server?
+10.1k Golang : Allow Cross-Origin Resource Sharing request
+5.3k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+18.5k Golang : How to make function callback or pass value from function as parameter?
+6.7k Golang : Squaring elements in array
+5.6k Golang : Detect variable or constant type
+10.5k Golang : Sieve of Eratosthenes algorithm
+7.8k Golang : Find relative luminance or color brightness
+11.8k Golang : Get month name from date example
+17.6k Golang : Check if a directory exist or not