You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
1.5 KiB

3 years ago
  1. package config
  2. type DB struct {
  3. Disable bool `mapstructure:"disable" json:"disable" yaml:"disable"`
  4. Type string `mapstructure:"type" json:"type" yaml:"type"`
  5. AliasName string `mapstructure:"alias-name" json:"alias-name" yaml:"alias-name"`
  6. Path string `mapstructure:"path" json:"path" yaml:"path"` // 服务器地址:端口
  7. Port string `mapstructure:"port" json:"port" yaml:"port"` //:端口
  8. Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
  9. Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"` // 数据库名
  10. Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库用户名
  11. Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
  12. MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
  13. MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
  14. LogMode string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` // 是否开启Gorm全局日志
  15. LogZap bool `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"`
  16. }
  17. func (m *DB) Dsn() string {
  18. return m.Username + ":" + m.Password + "@tcp(" + m.Path + ":" + m.Port + ")/" + m.Dbname + "?" + m.Config
  19. }