Exemplo n.º 1
0
func removeTag(tx *bolt.Tx, tagName string, objPrefix []byte, objId int64) error {
	tagoBucket := tx.Bucket(TagoBucket)
	tagoTagsBucket := tagoBucket.Bucket(TagoTagsBucket)

	objBucket, e := tagoTagsBucket.CreateBucketIfNotExists(objPrefix)
	if e != nil {
		return e
	}

	arr, e := getItemsFromBucket(objBucket, tagName)
	if e != nil {
		return e
	}

	sl := intarr.New(arr)
	if sl.In(int32(objId)) {
		sl = sl.Remove(int32(objId))
	}

	bts, e := sl.Encode()
	if e != nil {
		return e
	}
	e = objBucket.Put([]byte(tagName), bts)

	return e
}
Exemplo n.º 2
0
func setTag(tx *bolt.Tx, tagName string, objPrefix []byte, objId int64) error {
	tagoBucket := tx.Bucket(TagoBucket)
	tagoTagsBucket := tagoBucket.Bucket(TagoTagsBucket)

	objBucket, e := tagoTagsBucket.CreateBucketIfNotExists(objPrefix)
	if e != nil {
		return e
	}

	sl, e := getItemsFromBucket(objBucket, tagName)
	if e != nil {
		return e
	}

	// todo overflow int32
	sl = append(sl, objId)

	bts, e := intarr.New(sl).Encode()
	if e != nil {
		return e
	}
	e = objBucket.Put([]byte(tagName), bts)

	return e
}