Beispiel #1
0
func (cache *Cache) SaveGob(filepath string) {
	b := bytes.Buffer{}
	e := gob.NewEncoder(&b)
	err := e.Encode(cache)
	util.FatalIfErr(err)
	err = ioutil.WriteFile(filepath, b.Bytes(), 0644)
	util.FatalIfErr(err)
}
Beispiel #2
0
func LoadGob(filepath string) (cache Cache) {
	cache = Cache{}
	file, err := ioutil.ReadFile(filepath)
	b := bytes.Buffer{}
	b.Write(file)
	err = gob.NewDecoder(&b).Decode(&cache)
	util.FatalIfErr(err)
	return cache
}
Beispiel #3
0
func (cache *Cache) SaveJson(filepath string) {
	dat, err := json.Marshal(cache)
	util.FatalIfErr(err)
	ioutil.WriteFile(filepath, dat, 0644)
}