Beispiel #1
0
// ------- Init storage -----------
func initStorage() {
	var err error
	//TODO consensus requires persistent storage. Here we are using an in memory only. Fix it for real fault tolerance.
	storage, err = kv.CreateMem(new(kv.Options))
	if err != nil {
		log.Fatalln("initStorage error:", err)
	}
}
Beispiel #2
0
Datei: db.go Projekt: andrebq/exp
func openOrCreate(dbfile string) (*kv.DB, error) {
	opt := &kv.Options{VerifyDbBeforeOpen: true,
		VerifyDbAfterOpen:   true,
		VerifyDbBeforeClose: true,
		VerifyDbAfterClose:  true}

	if len(dbfile) == 0 {
		// in memory database
		return kv.CreateMem(opt)
	}
	_, err := os.Stat(dbfile)
	if os.IsNotExist(err) {
		return kv.Create(dbfile, opt)
	} else {
		return kv.Open(dbfile, opt)
	}
}