Skip to content

Instantly share code, notes, and snippets.

@robertgzr
Created September 21, 2016 21:52
Show Gist options
  • Save robertgzr/1955b38b89a361267f5b85489f5e2196 to your computer and use it in GitHub Desktop.
Save robertgzr/1955b38b89a361267f5b85489f5e2196 to your computer and use it in GitHub Desktop.
gob encoding/decoding
func Save(path string, obj interface{}) (err error) {
file, err := os.Create(path)
defer file.Close()
if err == nil {
encoder := gob.NewEncoder(file)
err = encoder.Encode(obj)
}
return
}
func Load(path string, obj interface{}) (err error) {
file, err := os.Open(path)
defer file.Close()
if err == nil {
decoder := gob.NewDecoder(file)
err = decoder.Decode(obj)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment