Ejemplo n.º 1
0
func getItemsFromBucket(bucket *bolt.Bucket, tagName string) ([]int64, error) {
	bts := bucket.Get([]byte(tagName))

	sl, e := intarr.Decode(bts)
	if e != nil {
		return nil, e
	}

	return sl.Int64(), e
}
Ejemplo n.º 2
0
func boltSetVote(tx *bolt.Tx, what []byte, who int, v vote) error {

	var (
		gollBucket = tx.Bucket(BucketGollName)
		whatBucket = gollBucket.Bucket(BucketWhatName)
		metaBucket = gollBucket.Bucket(BucketMetaName)
		//settingBucket = gollBucket.Bucket(BucketSettingName)
	)

	bts := whatBucket.Get(what)
	sl, e := intarr.Decode(bts)
	if e != nil {
		return e
	}
	sl = append(sl, int32(who))
	sl.Sort()

	bts, e = sl.Encode()
	if e != nil {
		return e
	}

	e = whatBucket.Put(what, bts)
	if e != nil {
		return e
	}

	bts = metaBucket.Get(what)
	meta, e := newMeta(bts)
	if e != nil {
		return e
	}
	meta.Total++
	meta.TotalUp += int(v)
	bts, e = meta.encode()
	if e != nil {
		return e
	}
	e = metaBucket.Put(what, bts)
	if e != nil {
		return e
	}

	return e
}
Ejemplo n.º 3
0
func boltVoted(tx *bolt.Tx, what []byte, who int) (voted bool, e error) {
	gollBucket := tx.Bucket(BucketGollName)
	whatBucket := gollBucket.Bucket(BucketWhatName)
	if whatBucket == nil {
		return // fmt.Errorf("Bucket is nil")
	}
	bts := whatBucket.Get(what)
	if bts == nil {
		return
	}
	slice, e := intarr.Decode(bts)
	if e != nil {
		return false, e
	}
	if slice.In(int32(who)) {
		voted = true
		return
	}
	return
}