Created
September 21, 2016 21:52
-
-
Save robertgzr/1955b38b89a361267f5b85489f5e2196 to your computer and use it in GitHub Desktop.
gob encoding/decoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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