29 lines
421 B
Go
29 lines
421 B
Go
|
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
|
||
|
}
|