本文整理汇总了Golang中github.com/boltdb/bolt.DB.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Close方法的具体用法?Golang DB.Close怎么用?Golang DB.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/boltdb/bolt.DB
的用法示例。
在下文中一共展示了DB.Close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SerializeIndex
func (c *Context) SerializeIndex(index *Index) (err error) {
var data []byte
var db *bolt.DB
if data, err = json.Marshal(index); err != nil {
return
}
db, err = c.OpenDB()
if err != nil {
return err
}
defer db.Close()
return db.Update(func(tx *bolt.Tx) error {
bucket, err := tx.CreateBucketIfNotExists(byteify(IndicesKey))
if err != nil {
return err
}
if bucket == nil {
return ErrNoSuchDbBucket
}
return bucket.Put(byteify(index.FileId), data)
})
}
示例2: NewHeap
// New creates a wait queue.
// The bucket will be created if it does not exist. Otherwise,
// the bucket will be deleted and created again.
func NewHeap(db *bolt.DB, bucket []byte, bufsize int) (h *Heap, err error) {
if err = db.Update(func(tx *bolt.Tx) error {
if tx.Bucket(bucket) != nil {
if err := tx.DeleteBucket(bucket); err != nil {
return err
}
}
if _, err := tx.CreateBucketIfNotExists(bucket); err != nil {
return err
}
return nil
}); err != nil {
db.Close()
return
}
h = &Heap{
db: db,
count: 0,
min: nil,
writebuf: list.New(),
bufsize: bufsize,
bucket: bucket,
}
return
}
示例3: tearDownBoltDB
// tearDownBoltDB closes and deletes boltdb
func tearDownBoltDB(db *bolt.DB) error {
p := db.Path()
err := db.Close()
if err != nil {
return err
}
return os.Remove(p)
}
示例4: closedb
// closedb closes and deletes a ReportifyDB database.
func closedb(db *bolt.DB) {
if db == nil {
return
}
path := db.Path()
db.Close()
if path != "" {
os.Remove(path)
}
}
示例5: Run
func Run(cfg config.Config) (err error) {
var db *bolt.DB
db, err = bolt.Open(cfg.DatabasePath, 0600, &bolt.Options{Timeout: cfg.Timeout})
if err != nil {
return err
}
defer func() {
if err == nil {
err = db.Close()
} else {
db.Close()
}
}()
return nil
}
示例6:
db, err = GetDB(pth)
Expect(err).To(BeNil())
u = NewUser(
"inspector",
UserPassword("abc123bs"),
UserPermission("write"),
UserDB(db),
)
_, err = u.Save()
Expect(err).To(BeNil())
})
AfterEach(func() {
db.Close()
os.RemoveAll(dir)
})
It("can save", func() {
u2 := NewUser("inspector", UserDB(db))
Expect(u2.Fetch()).To(BeNil())
Expect(u2.Password).To(Equal(""))
Expect(len(u2.HashedPassword)).ToNot(Equal(0))
Expect(u2.Permission).To(Equal("write"))
})
It("can delete", func() {
err := u.Delete()
Expect(err).To(BeNil())
u2 := NewUser("inspector", UserDB(db))
示例7: closeAndRemove
func closeAndRemove(db *bolt.DB, filename string) {
db.Close()
removeFile(filename)
}
示例8: closePageDatabase
func closePageDatabase(db *bolt.DB) {
if db != nil {
db.Close()
db = nil
}
}
示例9: clean_bolt
func clean_bolt(db *bolt.DB) {
db.Close()
os.Remove(db.Path())
}
示例10: closeDB
func closeDB(db *bolt.DB) {
db.Close()
if err := os.Remove(getDBPath()); err != nil {
panic(err)
}
}