encode

Encode/Decode Golang data to Gob files

Golang has a package called Gob to encode and decode values in to go specific binary format for transmiting as streams or for saving to file. Below are two functions, Load and Save to encode/decode go values including struct’s in to files. package main import ( "encoding/gob" "fmt" "os" "runtime" ) const file = "/tmp/test.gob" type User struct { Name, Pass string } func main(){ var datato = &User{"Donald","DuckPass"} var datafrom = new(User) err := Save(file, datato) Check(err) err = Load(file, datafrom) Check(err) fmt.