storj/storage/boltdb/client.go

41 lines
713 B
Go
Raw Normal View History

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
2018-04-06 17:32:34 +01:00
package boltdb
import (
"time"
"github.com/boltdb/bolt"
2018-04-06 17:32:34 +01:00
)
var (
defaultTimeout = 1 * time.Second
ErrDbOpen = Error.New("error boltdb failed to open")
ErrInitDb = Error.New("error instantiating boltdb")
)
2018-04-06 17:32:34 +01:00
// Client is the storage interface for the Bolt database
type Client struct {
db *bolt.DB
Path string
2018-04-06 17:32:34 +01:00
}
// New instantiates a new BoltDB client
func New(path string) (*Client, error) {
db, err := bolt.Open(path, 0600, &bolt.Options{Timeout: defaultTimeout})
2018-04-06 17:32:34 +01:00
if err != nil {
return nil, ErrDbOpen
2018-04-06 17:32:34 +01:00
}
return &Client{
db: db,
Path: path,
2018-04-06 17:32:34 +01:00
}, nil
}
func (c *Client) Close() error {
return c.db.Close()
}