db_list.go 1.9 KB

1234567891011121314151617181920212223242526272829303132
  1. package config
  2. type DsnProvider interface {
  3. Dsn() string
  4. }
  5. // Embeded 结构体可以压平到上一层,从而保持 config 文件的结构和原来一样
  6. // 见 playground: https://go.dev/play/p/KIcuhqEoxmY
  7. // GeneralDB 也被 Pgsql 和 Mysql 原样使用
  8. type GeneralDB struct {
  9. Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"`
  10. Port string `mapstructure:"port" json:"port" yaml:"port"`
  11. Config string `mapstructure:"config" json:"config" yaml:"config"` // 高级配置
  12. Dbname string `mapstructure:"db-name" json:"db-name" yaml:"db-name"` // 数据库名
  13. Username string `mapstructure:"username" json:"username" yaml:"username"` // 数据库密码
  14. Password string `mapstructure:"password" json:"password" yaml:"password"` // 数据库密码
  15. Path string `mapstructure:"path" json:"path" yaml:"path"`
  16. Engine string `mapstructure:"engine" json:"engine" yaml:"engine" default:"InnoDB"` //数据库引擎,默认InnoDB
  17. LogMode string `mapstructure:"log-mode" json:"log-mode" yaml:"log-mode"` // 是否开启Gorm全局日志
  18. MaxIdleConns int `mapstructure:"max-idle-conns" json:"max-idle-conns" yaml:"max-idle-conns"` // 空闲中的最大连接数
  19. MaxOpenConns int `mapstructure:"max-open-conns" json:"max-open-conns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
  20. Singular bool `mapstructure:"singular" json:"singular" yaml:"singular"` //是否开启全局禁用复数,true表示开启
  21. LogZap bool `mapstructure:"log-zap" json:"log-zap" yaml:"log-zap"` // 是否通过zap写入日志文件
  22. }
  23. type SpecializedDB struct {
  24. Type string `mapstructure:"type" json:"type" yaml:"type"`
  25. AliasName string `mapstructure:"alias-name" json:"alias-name" yaml:"alias-name"`
  26. GeneralDB `yaml:",inline" mapstructure:",squash"`
  27. Disable bool `mapstructure:"disable" json:"disable" yaml:"disable"`
  28. }