bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/csconfig/database.go (about)

     1  package csconfig
     2  
     3  import (
     4  	"fmt"
     5  
     6  	log "github.com/sirupsen/logrus"
     7  )
     8  
     9  type DatabaseCfg struct {
    10  	User     string      `yaml:"user"`
    11  	Password string      `yaml:"password"`
    12  	DbName   string      `yaml:"db_name"`
    13  	Host     string      `yaml:"host"`
    14  	Port     int         `yaml:"port"`
    15  	DbPath   string      `yaml:"db_path"`
    16  	Type     string      `yaml:"type"`
    17  	Flush    *FlushDBCfg `yaml:"flush"`
    18  	LogLevel *log.Level  `yaml:"log_level"`
    19  }
    20  
    21  type FlushDBCfg struct {
    22  	MaxItems *int    `yaml:"max_items"`
    23  	MaxAge   *string `yaml:"max_age"`
    24  }
    25  
    26  func (c *Config) LoadDBConfig() error {
    27  	if c.DbConfig == nil {
    28  		return fmt.Errorf("no database configuration provided")
    29  	}
    30  
    31  	if c.Cscli != nil {
    32  		c.Cscli.DbConfig = c.DbConfig
    33  	}
    34  
    35  	if c.API != nil && c.API.Server != nil {
    36  		c.API.Server.DbConfig = c.DbConfig
    37  	}
    38  
    39  	return nil
    40  }