/
bootstrapper.go
38 lines (32 loc) · 1.12 KB
/
bootstrapper.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
package leveldb
import (
"github.com/centrifuge/go-centrifuge/bootstrap"
"github.com/centrifuge/go-centrifuge/errors"
"github.com/centrifuge/go-centrifuge/storage"
)
// Config holds configuration data for storage package
type Config interface {
GetStoragePath() string
GetConfigStoragePath() string
SetDefault(key string, value interface{})
}
// Bootstrapper implements bootstrapper.Bootstrapper.
type Bootstrapper struct{}
// Bootstrap initialises the levelDB.
func (*Bootstrapper) Bootstrap(context map[string]interface{}) error {
if _, ok := context[bootstrap.BootstrappedConfig]; !ok {
return errors.New("config not initialised")
}
cfg := context[bootstrap.BootstrappedConfig].(Config)
configLevelDB, err := NewLevelDBStorage(cfg.GetConfigStoragePath())
if err != nil {
return errors.New("failed to init config level db: %v", err)
}
context[storage.BootstrappedConfigDB] = NewLevelDBRepository(configLevelDB)
levelDB, err := NewLevelDBStorage(cfg.GetStoragePath())
if err != nil {
return errors.New("failed to init level db: %v", err)
}
context[storage.BootstrappedDB] = NewLevelDBRepository(levelDB)
return nil
}