refactor: slog替换logrus、日志操作统一、支持json、text格式等

This commit is contained in:
meilin.huang
2023-09-02 17:24:18 +08:00
parent d51cd4b289
commit 899a3a8243
47 changed files with 685 additions and 293 deletions

View File

@@ -1,5 +1,7 @@
package config
import "mayfly-go/pkg/logx"
type Mysql struct {
AutoMigration bool `mapstructure:"auto-migration" json:"autoMigration" yaml:"auto-migration"`
Host string `mapstructure:"path" json:"host" yaml:"host"`
@@ -13,6 +15,19 @@ type Mysql struct {
LogZap string `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"`
}
func (m *Mysql) Default() {
if m.Host == "" {
m.Host = "localhost:3306"
logx.Warnf("未配置mysql.host, 默认值: %s", m.Host)
}
if m.Config == "" {
m.Config = "charset=utf8&loc=Local&parseTime=true"
}
if m.MaxIdleConns == 0 {
m.MaxIdleConns = 5
}
}
func (m *Mysql) Dsn() string {
return m.Username + ":" + m.Password + "@tcp(" + m.Host + ")/" + m.Dbname + "?" + m.Config
}