Golang bytes.Reader.ReadByte() function example
package bytes
Read 1 byte from the reader and return the 1 byte and error message. Most often the error is nil.
Golang bytes.Reader.ReadByte() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
reader := bytes.NewReader([]byte("abc"))
var b1, b2 byte
b1, err := reader.ReadByte() // read 1 byte
b2, err2 := reader.ReadByte() // read another 1 byte
fmt.Printf("%v %s \n", err, string(b1))
fmt.Printf("%v %s \n", err2, string(b2))
}
Output :
<nil> a
<nil> b
Reference :
Advertisement
Something interesting
Tutorials
+6.2k Golang : Calculate US Dollar Index (DXY)
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+17.4k Golang : Check if IP address is version 4 or 6
+5.3k Javascript : Change page title to get viewer attention
+11.2k Golang : Fix - does not implement sort.Interface (missing Len method)
+15.6k Golang : rune literal not terminated error
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+7.3k Golang : Not able to grep log.Println() output
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+26.9k Golang : Force your program to run with root permissions
+23.1k Golang : Randomly pick an item from a slice/array example