Golang encoding/json.Decoder.Buffered() function example
package encoding/json
Buffered returns a reader of the data remaining in the Decoder's buffer. The reader is valid until the next call to Decode.
Golang encoding/json.Decoder.Buffered() function usage example
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
)
func main() {
reader := strings.NewReader(`{"Name" : "Adam"} extra string to be buffered`)
var m struct {
Name string
}
decoder := json.NewDecoder(reader)
err := decoder.Decode(&m)
if err != nil {
fmt.Println(err)
}
extraString, err := ioutil.ReadAll(decoder.Buffered()) // read the remainder
if err != nil {
fmt.Println(err)
}
fmt.Println(string(extraString))
}
Output :
extra string to be buffered
Reference :
Advertisement
Something interesting
Tutorials
+9.2k Golang : does not implement flag.Value (missing Set method)
+6.1k PageSpeed : Clear or flush cache on web server
+6.6k Golang : How to determine if request or crawl is from Google robots
+29.5k Golang : Saving(serializing) and reading file with GOB
+30.9k Golang : Interpolating or substituting variables in string examples
+6.1k Golang : Create new color from command line parameters
+9.6k Golang : Copy map(hash table) example
+16.9k Golang : Read integer from file into array
+6.5k Unix/Linux : How to get own IP address ?
+3.7k Golang : Switch Redis database redis.NewClient
+9.7k Random number generation with crypto/rand in Go
+6.9k Mac OSX : Find large files by size