qurl/storage/bolt/bolt.go

29 lines
421 B
Go
Raw Normal View History

2018-11-11 16:56:30 -09:00
package bolt
import (
bolt "go.etcd.io/bbolt"
"net/url"
"time"
)
type BoltStorage struct {
DB *bolt.DB
}
func (stor *BoltStorage) Shutdown() {
stor.DB.Close()
}
func New(u *url.URL) (*BoltStorage, error) {
path := u.Opaque
if u.Path != "" {
path = u.Path
}
db, err := bolt.Open(path, 0600, &bolt.Options{Timeout: 3 * time.Second})
if err != nil {
return nil, err
}
return &BoltStorage{DB: db}, nil
}