修改包名
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.toowon.com/jimmy/go-commom/middleware"
|
||||
"git.toowon.com/jimmy/go-common/middleware"
|
||||
)
|
||||
|
||||
// Config 应用配置
|
||||
@@ -18,6 +18,7 @@ type Config struct {
|
||||
MinIO *MinIOConfig `json:"minio"`
|
||||
Email *EmailConfig `json:"email"`
|
||||
SMS *SMSConfig `json:"sms"`
|
||||
Logger *LoggerConfig `json:"logger"`
|
||||
}
|
||||
|
||||
// DatabaseConfig 数据库配置
|
||||
@@ -218,6 +219,24 @@ type SMSConfig struct {
|
||||
Timeout int `json:"timeout"`
|
||||
}
|
||||
|
||||
// LoggerConfig 日志配置
|
||||
type LoggerConfig struct {
|
||||
// Level 日志级别: debug, info, warn, error
|
||||
Level string `json:"level"`
|
||||
|
||||
// Output 输出方式: stdout, stderr, file, both
|
||||
Output string `json:"output"`
|
||||
|
||||
// FilePath 日志文件路径(当output为file或both时必需)
|
||||
FilePath string `json:"filePath"`
|
||||
|
||||
// Prefix 日志前缀
|
||||
Prefix string `json:"prefix"`
|
||||
|
||||
// DisableTimestamp 禁用时间戳
|
||||
DisableTimestamp bool `json:"disableTimestamp"`
|
||||
}
|
||||
|
||||
// LoadFromFile 从文件加载配置
|
||||
// filePath: 配置文件路径(支持绝对路径和相对路径)
|
||||
func LoadFromFile(filePath string) (*Config, error) {
|
||||
@@ -342,6 +361,16 @@ func (c *Config) setDefaults() {
|
||||
c.SMS.Timeout = 10
|
||||
}
|
||||
}
|
||||
|
||||
// 日志默认值
|
||||
if c.Logger != nil {
|
||||
if c.Logger.Level == "" {
|
||||
c.Logger.Level = "info"
|
||||
}
|
||||
if c.Logger.Output == "" {
|
||||
c.Logger.Output = "stdout"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetDatabase 获取数据库配置
|
||||
@@ -390,6 +419,11 @@ func (c *Config) GetSMS() *SMSConfig {
|
||||
return c.SMS
|
||||
}
|
||||
|
||||
// GetLogger 获取日志配置
|
||||
func (c *Config) GetLogger() *LoggerConfig {
|
||||
return c.Logger
|
||||
}
|
||||
|
||||
// GetDatabaseDSN 获取数据库连接字符串
|
||||
func (c *Config) GetDatabaseDSN() (string, error) {
|
||||
if c.Database == nil {
|
||||
|
||||
@@ -69,6 +69,13 @@
|
||||
"templateCode": "SMS_123456789",
|
||||
"endpoint": "",
|
||||
"timeout": 10
|
||||
},
|
||||
"logger": {
|
||||
"level": "info",
|
||||
"output": "stdout",
|
||||
"filePath": "",
|
||||
"prefix": "app",
|
||||
"disableTimestamp": false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user