storj/storage/boltdb/client.go

47 lines
806 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"
"go.uber.org/zap"
2018-04-06 17:32:34 +01:00
)
var (
defaultTimeout = 1 * time.Second
)
2018-04-06 17:32:34 +01:00
const (
// fileMode sets permissions so owner can read and write
fileMode = 0600
)
2018-04-06 17:32:34 +01:00
// Client is the storage interface for the Bolt database
type Client struct {
logger *zap.Logger
db *bolt.DB
Path string
2018-04-06 17:32:34 +01:00
}
// New instantiates a new BoltDB client
func New(logger *zap.Logger, path string) (*Client, error) {
db, err := bolt.Open(path, fileMode, &bolt.Options{Timeout: defaultTimeout})
2018-04-06 17:32:34 +01:00
if err != nil {
return nil, err
2018-04-06 17:32:34 +01:00
}
return &Client{
logger: logger,
db: db,
Path: path,
2018-04-06 17:32:34 +01:00
}, nil
}
// Close closes a BoltDB client
func (c *Client) Close() error {
return c.db.Close()
}