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
+4.6k JavaScript : Rounding number to decimal formats to display currency
+31.5k Golang : bufio.NewReader.ReadLine to read file line by line
+7.3k Golang : Not able to grep log.Println() output
+28k Golang : Move file to another directory
+20.6k Golang : Secure(TLS) connection between server and client
+9.5k Golang : Get all countries currencies code in JSON format
+14.4k Golang : How to filter a map's elements for faster lookup
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+14.6k Golang : How to get URL port?
+14.6k Golang : GUI with Qt and OpenCV to capture image from camera
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date
+12k Golang : Find and draw contours with OpenCV example