Let DB be closed when not in use
This commit is contained in:
parent
24ca043895
commit
a617c771d9
18
boltrest.go
18
boltrest.go
@ -23,22 +23,36 @@ type DB struct {
|
||||
apiToken string
|
||||
remoteMD5 string
|
||||
online bool
|
||||
isOpen bool
|
||||
localDB *bolt.DB
|
||||
}
|
||||
|
||||
// Open returns the DB object
|
||||
func Open(filename string) (*DB, error) {
|
||||
// Create returns the DB object
|
||||
func Create(filename string) (*DB, error) {
|
||||
var err error
|
||||
b := DB{localFile: filename}
|
||||
b.localDB, err = bolt.Open(filename, 0644, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer b.localDB.Close()
|
||||
// Go ahead and make sure it's fresh
|
||||
b.RefreshDB()
|
||||
return &b, nil
|
||||
}
|
||||
|
||||
// Open opens the DB so things can be done
|
||||
func (b *DB) Open() error {
|
||||
var err error
|
||||
b.localDB, err = Open(b.localFile, 0644, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// Close closes the DB
|
||||
func (b *DB) Close() error {
|
||||
return b.localDB.Close()
|
||||
}
|
||||
|
||||
// Offline sets this DB to offline mode
|
||||
// That means it won't try to sync anything
|
||||
func (b *DB) Offline() {
|
||||
|
Loading…
Reference in New Issue
Block a user