本文整理汇总了Golang中github.com/boltdb/bolt.Bucket.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Bucket.Get方法的具体用法?Golang Bucket.Get怎么用?Golang Bucket.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/boltdb/bolt.Bucket
的用法示例。
在下文中一共展示了Bucket.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getEncodedObject
func getEncodedObject(bucket *bolt.Bucket, key string, value interface{}) error {
data := bucket.Get([]byte(key))
if data == nil {
return ObjectNotFoundErr
}
return json.Unmarshal(data, &value)
}
示例2: targetAdjustmentBase
// targetAdjustmentBase returns the magnitude that the target should be
// adjusted by before a clamp is applied.
func (cs *ConsensusSet) targetAdjustmentBase(blockMap *bolt.Bucket, pb *processedBlock) *big.Rat {
// Grab the block that was generated 'TargetWindow' blocks prior to the
// parent. If there are not 'TargetWindow' blocks yet, stop at the genesis
// block.
var windowSize types.BlockHeight
parent := pb.Block.ParentID
current := pb.Block.ID()
for windowSize = 0; windowSize < types.TargetWindow && parent != (types.BlockID{}); windowSize++ {
current = parent
copy(parent[:], blockMap.Get(parent[:])[:32])
}
timestamp := types.Timestamp(encoding.DecUint64(blockMap.Get(current[:])[40:48]))
// The target of a child is determined by the amount of time that has
// passed between the generation of its immediate parent and its
// TargetWindow'th parent. The expected amount of seconds to have passed is
// TargetWindow*BlockFrequency. The target is adjusted in proportion to how
// time has passed vs. the expected amount of time to have passed.
//
// The target is converted to a big.Rat to provide infinite precision
// during the calculation. The big.Rat is just the int representation of a
// target.
timePassed := pb.Block.Timestamp - timestamp
expectedTimePassed := types.BlockFrequency * windowSize
return big.NewRat(int64(timePassed), int64(expectedTimePassed))
}
示例3: Params
// Params returns the currently stored configuration parameters for hook h
// from bucket b.
func (RateLimitFilter) Params(h Hook, b *bolt.Bucket) map[string]string {
m := make(map[string]string)
for _, k := range []string{"amount", "interval"} {
m[k] = string(b.Get([]byte(fmt.Sprintf("%s-%s", h.ID, k))))
}
return m
}
示例4: addCityToIndex
func addCityToIndex(
bucket *bolt.Bucket, id string, name string, locale string, population uint32,
) error {
var err error
var cityName *ds.CityName
if locale == "" {
locale = "en"
}
cityNameKey := []byte(ds.PrepareCityNameKey(name))
if conflict := bucket.Get(cityNameKey); conflict != nil {
cityName, err = ds.CityNameFromString(string(cityNameKey), string(conflict))
if strconv.Itoa(cityName.CityId) != id {
cityNameKey = []byte(string(cityNameKey) + "|" + id)
}
}
err = bucket.Put(
cityNameKey, []byte(
name+"\t"+id+"\t"+locale+"\t"+strconv.Itoa(int(population)),
),
)
return err
}
示例5: Params
// Params returns the currently stored configuration parameters for hook h
// from bucket b.
func (ForwardRequestAction) Params(h Hook, b *bolt.Bucket) map[string]string {
m := make(map[string]string)
for _, k := range []string{"url"} {
m[k] = string(b.Get([]byte(fmt.Sprintf("%s-%s", h.ID, k))))
}
return m
}
示例6: earliestChildTimestamp
// earliestChildTimestamp returns the earliest timestamp that a child node
// can have while still being valid. See section 'Timestamp Rules' in
// Consensus.md.
//
// To boost performance, earliestChildTimestamp is passed a bucket that it can
// use from inside of a boltdb transaction.
func earliestChildTimestamp(blockMap *bolt.Bucket, pb *processedBlock) types.Timestamp {
// Get the previous MedianTimestampWindow timestamps.
windowTimes := make(types.TimestampSlice, types.MedianTimestampWindow)
windowTimes[0] = pb.Block.Timestamp
parent := pb.Parent
for i := uint64(1); i < types.MedianTimestampWindow; i++ {
// If the genesis block is 'parent', use the genesis block timestamp
// for all remaining times.
if parent == (types.BlockID{}) {
windowTimes[i] = windowTimes[i-1]
continue
}
// Get the next parent's bytes. Because the ordering is specific, the
// parent does not need to be decoded entirely to get the desired
// information. This provides a performance boost. The id of the next
// parent lies at the first 32 bytes, and the timestamp of the block
// lies at bytes 40-48.
parentBytes := blockMap.Get(parent[:])
copy(parent[:], parentBytes[:32])
windowTimes[i] = types.Timestamp(encoding.DecUint64(parentBytes[40:48]))
}
sort.Sort(windowTimes)
// Return the median of the sorted timestamps.
return windowTimes[len(windowTimes)/2]
}
示例7: Params
// Params returns the currently stored configuration parameters for hook h
// from bucket b.
func (ExecuteAction) Params(h Hook, b *bolt.Bucket) map[string]string {
m := make(map[string]string)
for _, k := range []string{"command"} {
m[k] = string(b.Get([]byte(fmt.Sprintf("%s-%s", h.ID, k))))
}
return m
}
示例8: Params
// Params returns the currently stored configuration parameters for hook h
// from bucket b.
func (EmailAction) Params(h Hook, b *bolt.Bucket) map[string]string {
m := make(map[string]string)
for _, k := range []string{"token", "domain", "address", "subject", "template"} {
m[k] = string(b.Get([]byte(fmt.Sprintf("%s-%s", h.ID, k))))
}
return m
}
示例9: getGrantScopes
func getGrantScopes(bucket *bolt.Bucket, grant string) map[string]bool {
scopesByte := bucket.Get([]byte(grant))
if scopesByte == nil {
return nil
}
return database.StringToSet(string(scopesByte))
}
示例10: size
func (store *BoltStore) size(bucket *bolt.Bucket, key string, size *AtomicInt64) int64 {
var statics *AtomicInt64 = size
if statics == nil {
statics = NewAtomicInt64(0)
}
if key != "" {
b := bucket.Get([]byte(key))
if b != nil {
return statics.Caculate(int64(len(key) + len(b)))
}
bucket = bucket.Bucket([]byte(key))
}
if bucket != nil {
c := bucket.Cursor()
// to do staticsing
for k, v := c.First(); k != nil; k, v = c.Next() {
if v != nil {
statics.Caculate(int64(len(k) + len(v)))
} else {
store.size(bucket, string(k), statics)
}
}
statics.Caculate(int64(len(key)))
return statics.Value()
}
//! null
return statics.Value()
}
示例11: get
func (store *BoltStore) get(bucket *bolt.Bucket, key string, nested bool) (interface{}, error) {
if key != "" {
b := bucket.Get([]byte(key))
if b != nil {
return store.coder.Decode(b)
}
bucket = bucket.Bucket([]byte(key))
}
if bucket != nil {
m := make(map[string]interface{})
c := bucket.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
if v != nil {
vv, err := store.coder.Decode(v)
if err != nil {
return nil, err
}
m[string(k)] = vv
}
if v == nil && nested == true {
vv, err := store.get(bucket, string(k), nested)
if err != nil {
return nil, err
}
m[string(k)] = vv
}
}
return m, nil
}
return nil, fmt.Errorf("bucket not exist")
}
示例12: storeWords
// Store a word,word -> word sequence
func storeWords(bucket *bolt.Bucket, word1, word2, word3 string) error {
key := []byte(word1 + " " + word2)
// Get value from bucket and decode it
rawValue := bucket.Get(key)
var value []string
if rawValue == nil {
value = make([]string, 0, 1)
} else {
if err := json.Unmarshal(rawValue, &value); err != nil {
log.Printf("Cannot decode raw value for key '%v': %v; starting new empty key; old value is: %v", string(key), string(rawValue))
value = make([]string, 0, 1)
}
}
// Add new word to value
value = append(value, word3)
// Encode value and store it in bucket
rawValue, err := json.Marshal(value)
if err != nil {
return err
}
if err := bucket.Put(key, rawValue); err != nil {
return err
}
// All done
return nil
}
示例13: getData
func (this *DB) getData(bucket *bolt.Bucket) (map[string]int, ipQueue, error) {
var addrQ ipQueue
heapRaw := bucket.Get(boltAddrHeapKey)
if heapRaw == nil {
addrQ = ipQueue(make([]*ipEntry, 0, 1))
} else {
dec := gob.NewDecoder(bytes.NewReader(heapRaw))
if err := dec.Decode(&addrQ); err != nil {
return nil, nil, err
}
}
var addrMap map[string]int
mapRaw := bucket.Get(boltAddrMapKey)
if mapRaw == nil {
addrMap = make(map[string]int)
} else {
dec := gob.NewDecoder(bytes.NewReader(mapRaw))
if err := dec.Decode(&addrMap); err != nil {
return nil, nil, err
}
}
return addrMap, addrQ, nil
}
示例14: Params
// Params returns the currently stored configuration parameters for hook h
// from bucket b.
func (GithubValidator) Params(h Hook, b *bolt.Bucket) map[string]string {
m := make(map[string]string)
for _, k := range []string{"secret"} {
m[k] = string(b.Get([]byte(fmt.Sprintf("%s-%s", h.ID, k))))
}
return m
}
示例15: fetchChanCommitKeys
func fetchChanCommitKeys(nodeChanBucket *bolt.Bucket, channel *OpenChannel) error {
// Construct the key which stores the commitment keys: ckk || channelID.
// TODO(roasbeef): factor into func
var bc bytes.Buffer
if err := writeOutpoint(&bc, channel.ChanID); err != nil {
return err
}
commitKey := make([]byte, len(commitKeys)+bc.Len())
copy(commitKey[:3], commitKeys)
copy(commitKey[3:], bc.Bytes())
var err error
keyBytes := nodeChanBucket.Get(commitKey)
channel.TheirCommitKey, err = btcec.ParsePubKey(keyBytes[:33], btcec.S256())
if err != nil {
return err
}
channel.OurCommitKey, err = btcec.ParsePubKey(keyBytes[33:], btcec.S256())
if err != nil {
return err
}
return nil
}