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.8k Unix/Linux : Get reboot history or check when was the last reboot date
+7.1k Golang : Squaring elements in array
+15.6k Golang : How to convert(cast) IP address to string?
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client
+12.1k Golang : Perform sanity checks on filename example
+17.7k Golang : Read data from config file and assign to variables
+20.2k Golang : How to get struct tag and use field name to retrieve data?
+6.8k Golang : Calculate pivot points for a cross
+9.8k Golang : Resumable upload to Google Drive(RESTful) example
+29.5k Golang : How to create new XML file ?
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.