func instrumentsFromDB(b *bolt.Bucket) { instruments = make([]Instrument, b.Stats().KeyN) i := 0 b.ForEach(func(k, v []byte) error { var inst Instrument buf := bytes.NewBuffer(v) dec := gob.NewDecoder(buf) err := dec.Decode(&inst) if err != nil { return err } instruments[inst.ID] = inst i++ return err }) }
func GetImgs() ([]img.Img, error) { var rawImg [][]byte var Imgs []img.Img var b *bolt.Bucket err := DB.Update(func(tx *bolt.Tx) error { var err error b, err = tx.CreateBucketIfNotExists([]byte("images")) if err != nil { return err } stats := b.Stats() if stats.KeyN > 0 { for i := 1; i <= stats.KeyN; i++ { x := b.Get([]byte(strconv.FormatInt(int64(i), 10))) rawImg = append(rawImg, x) } } return nil }) if err != nil { return Imgs, err } for _, d := range rawImg { var iimg img.Img err := json.Unmarshal(d, &iimg) if err != nil { panic(err) return Imgs, err } Imgs = append(Imgs, iimg) } return Imgs, nil }
func numKeys(bucket *bolt.Bucket) int { stats := bucket.Stats() return stats.KeyN }