示例#1
0
文件: bolt.go 项目: nickethier/bosun
func isMigrated(db *bolt.DB, name string) (bool, error) {
	found := false
	err := db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte(dbBucket))
		if b == nil {
			return fmt.Errorf("unknown bucket: %v", dbBucket)
		}
		if dat := b.Get([]byte("isMigrated:" + name)); dat != nil {
			found = true
		}
		return nil
	})
	return found, err
}
示例#2
0
文件: bolt.go 项目: nickethier/bosun
func decode(db *bolt.DB, name string, dst interface{}) error {
	var data []byte
	err := db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte(dbBucket))
		if b == nil {
			return fmt.Errorf("unknown bucket: %v", dbBucket)
		}
		data = b.Get([]byte(name))
		return nil
	})
	if err != nil {
		return err
	}
	gr, err := gzip.NewReader(bytes.NewReader(data))
	if err != nil {
		return err
	}
	defer gr.Close()
	return gob.NewDecoder(gr).Decode(dst)
}