Golang encoding/gob.Encoder.Encode() function example
package encoding/gob
Encode transmits the data item represented by the empty interface value, guaranteeing that all necessary type information has been transmitted first.
Golang encoding/gob.Encoder.Encode() function usage example
func encode_gob(data interface{}) ([]byte, error) {
buff := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buff)
err := enc.Encode(data) // <----- here
if err != nil {
return nil, err
}
return buff.Bytes(), err
}
References :
http://golang.org/pkg/encoding/gob/#Encoder.Encode
https://www.socketloop.com/references/golang-encoding-gob-newencoder-function-examples
Advertisement
Something interesting
Tutorials
+5.3k Golang : Pad file extension automagically
+10.1k Golang : Get login name from environment and prompt for password
+5.7k Golang : Error handling methods
+22.4k Golang : Read directory content with filepath.Walk()
+55.3k Golang : Unmarshal JSON from http response
+38.1k Golang : Read a text file and replace certain words
+9.6k Javascript : Read/parse JSON data from HTTP response
+8.3k Golang : Emulate NumPy way of creating matrix example
+10.5k Generate Random number with math/rand in Go
+15.2k Golang : Save(pipe) HTTP response into a file
+11k Golang : Replace a parameter's value inside a configuration file example
+29.9k Golang : How to get HTTP request header information?