chore(storage): support set db path for badger driver (#499)
* chore(storage): support set db path for badger driver Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * fix path Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * fix readme Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * update default value Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
ccc73947ad
commit
4e05611577
|
@ -170,6 +170,8 @@ stat:
|
||||||
path: "bunt.db"
|
path: "bunt.db"
|
||||||
leveldb:
|
leveldb:
|
||||||
path: "level.db"
|
path: "level.db"
|
||||||
|
badgerdb:
|
||||||
|
path: "badger.db"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Memory Usage
|
## Memory Usage
|
||||||
|
|
|
@ -88,6 +88,8 @@ stat:
|
||||||
path: "bunt.db"
|
path: "bunt.db"
|
||||||
leveldb:
|
leveldb:
|
||||||
path: "level.db"
|
path: "level.db"
|
||||||
|
badgerdb:
|
||||||
|
path: "badger.db"
|
||||||
`)
|
`)
|
||||||
|
|
||||||
// ConfYaml is config structure.
|
// ConfYaml is config structure.
|
||||||
|
@ -174,11 +176,12 @@ type SectionLog struct {
|
||||||
|
|
||||||
// SectionStat is sub section of config.
|
// SectionStat is sub section of config.
|
||||||
type SectionStat struct {
|
type SectionStat struct {
|
||||||
Engine string `yaml:"engine"`
|
Engine string `yaml:"engine"`
|
||||||
Redis SectionRedis `yaml:"redis"`
|
Redis SectionRedis `yaml:"redis"`
|
||||||
BoltDB SectionBoltDB `yaml:"boltdb"`
|
BoltDB SectionBoltDB `yaml:"boltdb"`
|
||||||
BuntDB SectionBuntDB `yaml:"buntdb"`
|
BuntDB SectionBuntDB `yaml:"buntdb"`
|
||||||
LevelDB SectionLevelDB `yaml:"leveldb"`
|
LevelDB SectionLevelDB `yaml:"leveldb"`
|
||||||
|
BadgerDB SectionBadgerDB `yaml:"badgerdb"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SectionRedis is sub section of config.
|
// SectionRedis is sub section of config.
|
||||||
|
@ -204,6 +207,11 @@ type SectionLevelDB struct {
|
||||||
Path string `yaml:"path"`
|
Path string `yaml:"path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SectionBadgerDB is sub section of config.
|
||||||
|
type SectionBadgerDB struct {
|
||||||
|
Path string `yaml:"path"`
|
||||||
|
}
|
||||||
|
|
||||||
// SectionPID is sub section of config.
|
// SectionPID is sub section of config.
|
||||||
type SectionPID struct {
|
type SectionPID struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
|
@ -321,6 +329,7 @@ func LoadConf(confPath string) (ConfYaml, error) {
|
||||||
conf.Stat.BoltDB.Bucket = viper.GetString("stat.boltdb.bucket")
|
conf.Stat.BoltDB.Bucket = viper.GetString("stat.boltdb.bucket")
|
||||||
conf.Stat.BuntDB.Path = viper.GetString("stat.buntdb.path")
|
conf.Stat.BuntDB.Path = viper.GetString("stat.buntdb.path")
|
||||||
conf.Stat.LevelDB.Path = viper.GetString("stat.leveldb.path")
|
conf.Stat.LevelDB.Path = viper.GetString("stat.leveldb.path")
|
||||||
|
conf.Stat.BadgerDB.Path = viper.GetString("stat.badgerdb.path")
|
||||||
|
|
||||||
// gRPC Server
|
// gRPC Server
|
||||||
conf.GRPC.Enabled = viper.GetBool("grpc.enabled")
|
conf.GRPC.Enabled = viper.GetBool("grpc.enabled")
|
||||||
|
|
|
@ -105,6 +105,7 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
|
||||||
|
|
||||||
assert.Equal(suite.T(), "bunt.db", suite.ConfGorushDefault.Stat.BuntDB.Path)
|
assert.Equal(suite.T(), "bunt.db", suite.ConfGorushDefault.Stat.BuntDB.Path)
|
||||||
assert.Equal(suite.T(), "level.db", suite.ConfGorushDefault.Stat.LevelDB.Path)
|
assert.Equal(suite.T(), "level.db", suite.ConfGorushDefault.Stat.LevelDB.Path)
|
||||||
|
assert.Equal(suite.T(), "badger.db", suite.ConfGorushDefault.Stat.BadgerDB.Path)
|
||||||
|
|
||||||
// gRPC
|
// gRPC
|
||||||
assert.Equal(suite.T(), false, suite.ConfGorushDefault.GRPC.Enabled)
|
assert.Equal(suite.T(), false, suite.ConfGorushDefault.GRPC.Enabled)
|
||||||
|
@ -180,6 +181,7 @@ func (suite *ConfigTestSuite) TestValidateConf() {
|
||||||
|
|
||||||
assert.Equal(suite.T(), "bunt.db", suite.ConfGorush.Stat.BuntDB.Path)
|
assert.Equal(suite.T(), "bunt.db", suite.ConfGorush.Stat.BuntDB.Path)
|
||||||
assert.Equal(suite.T(), "level.db", suite.ConfGorush.Stat.LevelDB.Path)
|
assert.Equal(suite.T(), "level.db", suite.ConfGorush.Stat.LevelDB.Path)
|
||||||
|
assert.Equal(suite.T(), "badger.db", suite.ConfGorush.Stat.BadgerDB.Path)
|
||||||
|
|
||||||
// gRPC
|
// gRPC
|
||||||
assert.Equal(suite.T(), false, suite.ConfGorush.GRPC.Enabled)
|
assert.Equal(suite.T(), false, suite.ConfGorush.GRPC.Enabled)
|
||||||
|
|
|
@ -75,3 +75,5 @@ stat:
|
||||||
path: "bunt.db"
|
path: "bunt.db"
|
||||||
leveldb:
|
leveldb:
|
||||||
path: "level.db"
|
path: "level.db"
|
||||||
|
badgerdb:
|
||||||
|
path: "badger.db"
|
||||||
|
|
|
@ -30,7 +30,12 @@ type Storage struct {
|
||||||
// Init client storage.
|
// Init client storage.
|
||||||
func (s *Storage) Init() error {
|
func (s *Storage) Init() error {
|
||||||
s.name = "badger"
|
s.name = "badger"
|
||||||
s.opts = badger.DefaultOptions(os.TempDir() + "badger")
|
dbPath := s.config.Stat.BadgerDB.Path
|
||||||
|
if dbPath == "" {
|
||||||
|
dbPath = os.TempDir() + "badger"
|
||||||
|
}
|
||||||
|
s.opts = badger.DefaultOptions(dbPath)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue