当前位置: 首页>>代码示例>>Golang>>正文


Golang Bucket.Bucket方法代码示例

本文整理汇总了Golang中github.com/boltdb/bolt.Bucket.Bucket方法的典型用法代码示例。如果您正苦于以下问题:Golang Bucket.Bucket方法的具体用法?Golang Bucket.Bucket怎么用?Golang Bucket.Bucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/boltdb/bolt.Bucket的用法示例。


在下文中一共展示了Bucket.Bucket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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()
}
开发者ID:h2object,项目名称:h2object,代码行数:32,代码来源:store_bolt.go

示例2: Get

func (store *BoltStore) Get(uri string, nested bool) (interface{}, error) {
	namespace, key := util.NamespaceKey(uri)
	bucketkeys := util.PathFolders(namespace)
	var bucket *bolt.Bucket = nil
	var result interface{}
	e := store.db.View(func(tx *bolt.Tx) error {
		for _, bucketkey := range bucketkeys {
			if bucket == nil {
				bucket = tx.Bucket([]byte(bucketkey))
				if bucket == nil {
					return errors.New(uri + " not exists")
				}
			} else {
				bucket = bucket.Bucket([]byte(bucketkey))
				if bucket == nil {
					return errors.New(uri + " not exists")
				}
			}
		}
		if bucket == nil {
			return errors.New(uri + " not exists")
		}

		val, err := store.get(bucket, key, nested)
		if err != nil {
			return err
		}
		result = val
		return nil
	})
	return result, e
}
开发者ID:h2object,项目名称:h2object,代码行数:32,代码来源:store_bolt.go

示例3: 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")
}
开发者ID:h2object,项目名称:h2object,代码行数:34,代码来源:store_bolt.go

示例4: MultiGet

func (store *BoltStore) MultiGet(uri string, suffix string, nested bool) ([]interface{}, error) {
	results := []interface{}{}
	bucketkeys := util.PathFolders(uri)
	var bucket *bolt.Bucket = nil
	e := store.db.View(func(tx *bolt.Tx) error {
		for _, bucketkey := range bucketkeys {
			if bucket == nil {
				bucket = tx.Bucket([]byte(bucketkey))
				if bucket == nil {
					return errors.New(uri + " not exists")
				}
			} else {
				bucket = bucket.Bucket([]byte(bucketkey))
				if bucket == nil {
					return errors.New(uri + " not exists")
				}
			}
		}
		if bucket == nil {
			return errors.New(uri + " not exists")
		}

		vals, err := store.multi_get(bucket, suffix, nested)
		if err != nil {
			return err
		}
		results = append(results, vals...)
		return nil
	})
	return results, e
}
开发者ID:h2object,项目名称:h2object,代码行数:31,代码来源:store_bolt.go

示例5: Size

func (store *BoltStore) Size(uri string) (int64, error) {
	namespace, key := util.NamespaceKey(uri)
	bucketkeys := util.PathFolders(namespace)
	var bucket *bolt.Bucket = nil
	var result int64 = 0
	e := store.db.View(func(tx *bolt.Tx) error {
		for _, bucketkey := range bucketkeys {
			if bucket == nil {
				bucket = tx.Bucket([]byte(bucketkey))
				if bucket == nil {
					return errors.New(uri + " not exists")
				}
			} else {
				bucket = bucket.Bucket([]byte(bucketkey))
				if bucket == nil {
					return errors.New(uri + " not exists")
				}
			}
		}
		if bucket == nil {
			return errors.New(uri + " not exists")
		}

		result = store.size(bucket, key, nil)
		return nil
	})
	return result, e
}
开发者ID:h2object,项目名称:h2object,代码行数:28,代码来源:store_bolt.go

示例6: Process

// Process verifies the signature and uniqueness of the random roken.
func (MailgunValidator) Process(h Hook, r Request, b *bolt.Bucket) error {
	// Check HMAC
	apikey := b.Get([]byte(fmt.Sprintf("%s-apikey", h.ID)))
	if apikey == nil {
		return errors.New("mailgun validator not initialized")
	}

	if r.Headers["Content-Type"] != "application/x-www-form-urlencoded" {
		return fmt.Errorf("unexpected Content-Type: %q", r.Headers["Content-Type"])
	}

	form, err := url.ParseQuery(string(r.Body))
	if err != nil {
		return fmt.Errorf("error parsing request body: %s", err)
	}

	timestamp := form.Get("timestamp")
	signature := []byte(form.Get("signature"))
	token := form.Get("token")

	mac := hmac.New(sha256.New, apikey)
	mac.Write([]byte(timestamp + token))
	expected := []byte(hex.EncodeToString(mac.Sum(nil)))
	if !hmac.Equal(signature, expected) {
		return errors.New("invalid signature")
	}

	// Check uniqueness
	tokens := b.Bucket([]byte("tokens"))
	if p := tokens.Get([]byte(token)); p != nil {
		return errors.New("duplicate request token received")
	}
	return tokens.Put([]byte(token), []byte{})
}
开发者ID:vampirewalk,项目名称:rehook,代码行数:35,代码来源:mailgun_validator.go

示例7: dig

func (self *TX) dig(keys [][]byte, create bool) (buckets []*bolt.Bucket, err error) {
	var bucket *bolt.Bucket
	if create {
		if bucket, err = self.tx.CreateBucketIfNotExists(keys[0]); err != nil {
			return
		}
	} else {
		if bucket = self.tx.Bucket(keys[0]); bucket == nil {
			err = ErrNotFound
			return
		}
	}
	buckets = append(buckets, bucket)
	for keys = keys[1:]; len(keys) > 0; keys = keys[1:] {
		if create {
			if bucket, err = bucket.CreateBucketIfNotExists(keys[0]); err != nil {
				return
			}
		} else {
			if bucket = bucket.Bucket(keys[0]); bucket == nil {
				err = ErrNotFound
				return
			}
		}
		buckets = append(buckets, bucket)
	}
	return
}
开发者ID:jmptrader,项目名称:unbolted,代码行数:28,代码来源:tx.go

示例8: multi_get

func (store *BoltStore) multi_get(bucket *bolt.Bucket, suffix string, nested bool) ([]interface{}, error) {
	results := []interface{}{}
	if bucket != nil {
		c := bucket.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if suffix == "" {
				if v != nil {
					vv, err := store.coder.Decode(v)
					if err != nil {
						return nil, err
					}
					results = append(results, vv)
					continue
				}

				if nested {
					bucket_nested := bucket.Bucket(k)
					if bucket_nested != nil {
						nests, err := store.multi_get(bucket_nested, suffix, nested)
						if err != nil {
							return results, err
						}
						results = append(results, nests...)
					}
				}
			} else {
				if strings.HasSuffix(string(k), suffix) {
					vv, err := store.get(bucket, string(k), true)
					if err != nil {
						return results, err
					}
					results = append(results, vv)
					continue
				} else {
					if nested && v == nil {
						bucket_nested := bucket.Bucket(k)
						if bucket_nested != nil {
							nests, err := store.multi_get(bucket_nested, suffix, nested)
							if err != nil {
								return results, err
							}
							results = append(results, nests...)
						}
					}
				}
			}
		}
	}
	return results, nil
}
开发者ID:h2object,项目名称:h2object,代码行数:50,代码来源:store_bolt.go

示例9: bucketFor

func bucketFor(key Key, b *bolt.Bucket) (*bolt.Bucket, []byte, error) {
	var err error
	elems, last := key.B()
	for _, e := range elems {
		// CreateBucketIfNotExists requires a writeable transaction.
		if new := b.Bucket(e); new != nil {
			b = new
			continue
		}
		if b, err = b.CreateBucket(e); err != nil {
			return b, last, err
		}
	}
	return b, last, nil
}
开发者ID:fluffle,项目名称:sp0rkle,代码行数:15,代码来源:bolt.go

示例10: walkBucket

func walkBucket(parent *bolt.Bucket, k []byte, v []byte, w io.Writer) error {
	if _, err := fmt.Fprintf(w, "%d:%x=%x\n", parent.Sequence(), k, v); err != nil {
		return err
	}

	// not a bucket, exit.
	if v != nil {
		return nil
	}
	return parent.ForEach(func(k, v []byte) error {
		if v == nil {
			return walkBucket(parent.Bucket(k), k, nil, w)
		}
		return walkBucket(parent, k, v, w)
	})
}
开发者ID:rgeronimi,项目名称:bolt,代码行数:16,代码来源:main_test.go

示例11: GetBucket

// GetBucket returns the given bucket below the current node.
func (n *node) GetBucket(tx *bolt.Tx, children ...string) *bolt.Bucket {
	var b *bolt.Bucket

	bucketNames := append(n.rootBucket, children...)
	for _, bucketName := range bucketNames {
		if b != nil {
			if b = b.Bucket([]byte(bucketName)); b == nil {
				return nil
			}
		} else {
			if b = tx.Bucket([]byte(bucketName)); b == nil {
				return nil
			}
		}
	}

	return b
}
开发者ID:asdine,项目名称:storm,代码行数:19,代码来源:bucket.go

示例12: NewUniqueIndex

// NewUniqueIndex loads a UniqueIndex
func NewUniqueIndex(parent *bolt.Bucket, indexName []byte) (*UniqueIndex, error) {
	var err error
	b := parent.Bucket(indexName)
	if b == nil {
		if !parent.Writable() {
			return nil, ErrNotFound
		}
		b, err = parent.CreateBucket(indexName)
		if err != nil {
			return nil, err
		}
	}

	return &UniqueIndex{
		IndexBucket: b,
		Parent:      parent,
	}, nil
}
开发者ID:asdine,项目名称:storm,代码行数:19,代码来源:unique.go

示例13: readBucket

func readBucket(b *bolt.Bucket) (*BoltBucket, error) {
	bb := new(BoltBucket)
	b.ForEach(func(k, v []byte) error {
		if v == nil {
			tb, err := readBucket(b.Bucket(k))
			tb.parent = bb
			if err == nil {
				tb.name = string(k)
				bb.buckets = append(bb.buckets, *tb)
			}
		} else {
			tp := BoltPair{key: string(k), val: string(v)}
			tp.parent = bb
			bb.pairs = append(bb.pairs, tp)
		}
		return nil
	})
	return bb, nil
}
开发者ID:jmptrader,项目名称:boltbrowser,代码行数:19,代码来源:bolt_model.go

示例14: walkBucket

func (cmd *CompactCommand) walkBucket(b *bolt.Bucket, keypath [][]byte, k, v []byte, seq uint64, fn walkFunc) error {
	// Execute callback.
	if err := fn(keypath, k, v, seq); err != nil {
		return err
	}

	// If this is not a bucket then stop.
	if v != nil {
		return nil
	}

	// Iterate over each child key/value.
	keypath = append(keypath, k)
	return b.ForEach(func(k, v []byte) error {
		if v == nil {
			bkt := b.Bucket(k)
			return cmd.walkBucket(bkt, keypath, k, nil, bkt.Sequence(), fn)
		}
		return cmd.walkBucket(b, keypath, k, v, b.Sequence(), fn)
	})
}
开发者ID:rgeronimi,项目名称:bolt,代码行数:21,代码来源:main.go

示例15: fill

func (b *Bucket) fill(bucket *bolt.Bucket) {
	//fmt.Println("Fill bucket ", bucket.Root())
	//fill subbuckets
	// bucket.Tx().ForEach(func(name []byte, buck *bolt.Bucket) error {
	// 	fmt.Println("subbucket ", string(name))
	// 	subbuck := Bucket{
	// 		Name: string(name),
	// 	}
	// 	fmt.Println("start fill ", string(name))
	// 	subbuck.fill(buck)

	// 	b.Subbuckets = append(b.Subbuckets, subbuck)
	// 	return nil
	// })

	//fill entries
	bucket.ForEach(func(k, v []byte) error {
		if len(v) == 0 { //subbucket
			sb := bucket.Bucket(k)
			if sb == nil {
				b.Entries = append(b.Entries, Entry{string(k), string(v)})
				return nil
			}

			subbuck := Bucket{
				Name:       string(k),
				Subbuckets: []Bucket{},
				Entries:    []Entry{},
			}
			subbuck.fill(sb)

			b.Subbuckets = append(b.Subbuckets, subbuck)

		} else {
			b.Entries = append(b.Entries, decodeEntry(k, v))
		}
		return nil
	})
}
开发者ID:geeksteam,项目名称:BoltGUI,代码行数:39,代码来源:boltgui.go


注:本文中的github.com/boltdb/bolt.Bucket.Bucket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。