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
+5.9k Golang : Use NLP to get sentences for each paragraph example
+14.8k Golang : Normalize unicode strings for comparison purpose
+6.1k Golang : How to write backslash in string?
+7.3k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+31.6k Golang : Get local IP and MAC address
+7.2k CloudFlare : Another way to get visitor's real IP address
+6.3k Golang : Test input string for unicode example
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+28.6k Golang : Read, Write(Create) and Delete Cookie example
+39.6k Golang : Remove dashes(or any character) from string
+5.1k Golang : Display packages names during compilation
+6.5k Golang : Map within a map example