gorm.go 1.4 KB

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