forked from hairyhenderson/gomplate
/
boltdb.go
37 lines (31 loc) · 917 Bytes
/
boltdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package libkv
import (
"net/url"
"time"
"github.com/docker/libkv"
"github.com/docker/libkv/store"
"github.com/docker/libkv/store/boltdb"
"github.com/hairyhenderson/gomplate/conv"
"github.com/hairyhenderson/gomplate/env"
)
// NewBoltDB - initialize a new BoltDB datasource handler
func NewBoltDB(u *url.URL) *LibKV {
boltdb.Register()
config := setupBoltDB(u.Fragment)
kv, err := libkv.NewStore(store.BOLTDB, []string{u.Path}, config)
if err != nil {
logFatal("BoltDB store creation failed", err)
}
return &LibKV{kv}
}
func setupBoltDB(bucket string) *store.Config {
if bucket == "" {
logFatal("missing bucket - must specify BoltDB bucket in URL fragment")
}
t := conv.MustParseInt(env.Getenv("BOLTDB_TIMEOUT"), 10, 16)
return &store.Config{
Bucket: bucket,
ConnectionTimeout: time.Duration(t) * time.Second,
PersistConnection: conv.Bool(env.Getenv("BOLTDB_PERSIST")),
}
}