コード例 #1
0
ファイル: data.go プロジェクト: jawspeak/go-project-tool
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)
}
コード例 #2
0
ファイル: data.go プロジェクト: jawspeak/go-project-tool
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
}
コード例 #3
0
ファイル: data.go プロジェクト: jawspeak/go-project-tool
func (cache *Cache) SaveJson(filepath string) {
	dat, err := json.Marshal(cache)
	util.FatalIfErr(err)
	ioutil.WriteFile(filepath, dat, 0644)
}