2020-11-30 09:37:17 +00:00
|
|
|
package csconfig
|
|
|
|
|
2021-03-24 17:16:17 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
2020-11-30 09:37:17 +00:00
|
|
|
|
|
|
|
type DatabaseCfg struct {
|
|
|
|
User string `yaml:"user"`
|
|
|
|
Password string `yaml:"password"`
|
|
|
|
DbName string `yaml:"db_name"`
|
2021-05-19 15:03:23 +00:00
|
|
|
Sslmode string `yaml:"sslmode"`
|
2020-11-30 09:37:17 +00:00
|
|
|
Host string `yaml:"host"`
|
|
|
|
Port int `yaml:"port"`
|
|
|
|
DbPath string `yaml:"db_path"`
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
Flush *FlushDBCfg `yaml:"flush"`
|
|
|
|
LogLevel *log.Level `yaml:"log_level"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type FlushDBCfg struct {
|
|
|
|
MaxItems *int `yaml:"max_items"`
|
|
|
|
MaxAge *string `yaml:"max_age"`
|
|
|
|
}
|
2021-03-24 17:16:17 +00:00
|
|
|
|
|
|
|
func (c *Config) LoadDBConfig() error {
|
|
|
|
if c.DbConfig == nil {
|
|
|
|
return fmt.Errorf("no database configuration provided")
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Cscli != nil {
|
|
|
|
c.Cscli.DbConfig = c.DbConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.API != nil && c.API.Server != nil {
|
|
|
|
c.API.Server.DbConfig = c.DbConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|