storj/storage/boltdb/client.go
2018-05-07 11:03:59 -06:00

36 lines
613 B
Go

package boltdb
import (
"errors"
"github.com/boltdb/bolt"
"time"
)
var (
defaultTimeout = 1 * time.Second
ErrDbOpen = errors.New("error boltdb failed to open")
ErrInitDb = errors.New("error instantiating boltdb")
)
// Client is the storage interface for the Bolt database
type Client struct {
db *bolt.DB
}
// New instantiates a new BoltDB client
func New(path string) (*Client, error) {
db, err := bolt.Open(path, 0600, &bolt.Options{Timeout: defaultTimeout})
if err != nil {
return nil, ErrDbOpen
}
return &Client{
db: db,
}, nil
}
func (c *Client) Close() error {
return c.db.Close()
}