|
|
|
@ -3,7 +3,6 @@ package common |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"io/ioutil" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"github.com/yedf/dtm/dtmcli" |
|
|
|
@ -23,7 +22,7 @@ type MicroService struct { |
|
|
|
} |
|
|
|
|
|
|
|
type Store struct { |
|
|
|
Driver string `yaml:"Driver"` |
|
|
|
Driver string `yaml:"Driver" default:"boltdb"` |
|
|
|
Host string `yaml:"Host"` |
|
|
|
Port int64 `yaml:"Port"` |
|
|
|
User string `yaml:"User"` |
|
|
|
@ -35,6 +34,10 @@ type Store struct { |
|
|
|
RedisPrefix string `yaml:"RedisPrefix" default:"{}"` // Redis storage prefix. stored to only one slot in cluster
|
|
|
|
} |
|
|
|
|
|
|
|
func (s *Store) IsDB() bool { |
|
|
|
return s.Driver == dtmcli.DBTypeMysql || s.Driver == dtmcli.DBTypePostgres |
|
|
|
} |
|
|
|
|
|
|
|
func (s *Store) GetDBConf() dtmcli.DBConf { |
|
|
|
return dtmcli.DBConf{ |
|
|
|
Driver: s.Driver, |
|
|
|
@ -60,10 +63,6 @@ type configType struct { |
|
|
|
// Config 配置
|
|
|
|
var Config = configType{} |
|
|
|
|
|
|
|
func getIntEnv(key string, defaultV string) int64 { |
|
|
|
return int64(dtmimp.MustAtoi(dtmimp.OrString(os.Getenv(key), defaultV))) |
|
|
|
} |
|
|
|
|
|
|
|
func MustLoadConfig() { |
|
|
|
loadFromEnv("", &Config) |
|
|
|
cont := []byte{} |
|
|
|
@ -91,8 +90,8 @@ func MustLoadConfig() { |
|
|
|
} |
|
|
|
|
|
|
|
func checkConfig() error { |
|
|
|
if Config.Store.Driver == "" { |
|
|
|
return errors.New("db driver empty") |
|
|
|
if Config.Store.Driver == "boltdb" { |
|
|
|
return nil |
|
|
|
} else if Config.Store.Driver == "redis" && (Config.Store.Host == "" || Config.Store.Port == 0) { |
|
|
|
return errors.New("db redis config not valid") |
|
|
|
} else if Config.Store.Driver != "redis" && (Config.Store.User == "" || Config.Store.Host == "" || Config.Store.Port == 0) { |
|
|
|
|