-
Notifications
You must be signed in to change notification settings - Fork 1
/
opt.go
45 lines (38 loc) · 809 Bytes
/
opt.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
38
39
40
41
42
43
44
45
package boltutils
import (
"os"
"github.com/boltdb/bolt"
)
type Opt func(db *DB) error
func Compression(ct CompressorType) func(db *DB) error {
return func(db *DB) error {
switch ct {
case GzipCompressor:
db.Compressor = newGzipCompressor()
case Lz4Compressor:
db.Compressor = newLz4Compressor()
}
return nil
}
}
func BoltDB(bdb *bolt.DB) Opt {
return func(db *DB) error {
db.DB = bdb
return nil
}
}
// Open open database file and return pointer of DB
func Open(path string, mode os.FileMode, options *bolt.Options) Opt {
return func(db *DB) error {
bdb, err := bolt.Open(path, mode, options)
if err != nil {
return err
}
db.DB = bdb
return nil
}
}
// OpenPath shortland for Open with single arg
func OpenPath(path string) Opt {
return Open(path, 0777, nil)
}