feat(架构): 完善基础架构设计
This commit is contained in:
@@ -12,6 +12,7 @@ type Config struct {
|
||||
Cache CacheConfig `mapstructure:"cache"`
|
||||
Logger LoggerConfig `mapstructure:"logger"`
|
||||
JWT JWTConfig `mapstructure:"jwt"`
|
||||
SMS SMSConfig `mapstructure:"sms"`
|
||||
RateLimit RateLimitConfig `mapstructure:"ratelimit"`
|
||||
Monitoring MonitoringConfig `mapstructure:"monitoring"`
|
||||
Health HealthConfig `mapstructure:"health"`
|
||||
@@ -42,6 +43,7 @@ type DatabaseConfig struct {
|
||||
MaxOpenConns int `mapstructure:"max_open_conns"`
|
||||
MaxIdleConns int `mapstructure:"max_idle_conns"`
|
||||
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
|
||||
AutoMigrate bool `mapstructure:"auto_migrate"`
|
||||
}
|
||||
|
||||
// RedisConfig Redis配置
|
||||
@@ -67,14 +69,15 @@ type CacheConfig struct {
|
||||
|
||||
// LoggerConfig 日志配置
|
||||
type LoggerConfig struct {
|
||||
Level string `mapstructure:"level"`
|
||||
Format string `mapstructure:"format"`
|
||||
Output string `mapstructure:"output"`
|
||||
FilePath string `mapstructure:"file_path"`
|
||||
MaxSize int `mapstructure:"max_size"`
|
||||
MaxBackups int `mapstructure:"max_backups"`
|
||||
MaxAge int `mapstructure:"max_age"`
|
||||
Compress bool `mapstructure:"compress"`
|
||||
Level string `mapstructure:"level"`
|
||||
Format string `mapstructure:"format"`
|
||||
Output string `mapstructure:"output"`
|
||||
FilePath string `mapstructure:"file_path"`
|
||||
MaxSize int `mapstructure:"max_size"`
|
||||
MaxBackups int `mapstructure:"max_backups"`
|
||||
MaxAge int `mapstructure:"max_age"`
|
||||
Compress bool `mapstructure:"compress"`
|
||||
UseColor bool `mapstructure:"use_color"`
|
||||
}
|
||||
|
||||
// JWTConfig JWT配置
|
||||
@@ -119,12 +122,12 @@ type ResilienceConfig struct {
|
||||
|
||||
// DevelopmentConfig 开发配置
|
||||
type DevelopmentConfig struct {
|
||||
Debug bool `mapstructure:"debug"`
|
||||
EnableProfiler bool `mapstructure:"enable_profiler"`
|
||||
EnableCors bool `mapstructure:"enable_cors"`
|
||||
CorsOrigins string `mapstructure:"cors_allowed_origins"`
|
||||
CorsMethods string `mapstructure:"cors_allowed_methods"`
|
||||
CorsHeaders string `mapstructure:"cors_allowed_headers"`
|
||||
Debug bool `mapstructure:"debug"`
|
||||
EnableProfiler bool `mapstructure:"enable_profiler"`
|
||||
EnableCors bool `mapstructure:"enable_cors"`
|
||||
CorsOrigins string `mapstructure:"cors_allowed_origins"`
|
||||
CorsMethods string `mapstructure:"cors_allowed_methods"`
|
||||
CorsHeaders string `mapstructure:"cors_allowed_headers"`
|
||||
}
|
||||
|
||||
// AppConfig 应用程序配置
|
||||
@@ -134,6 +137,26 @@ type AppConfig struct {
|
||||
Env string `mapstructure:"env"`
|
||||
}
|
||||
|
||||
// SMSConfig 短信配置
|
||||
type SMSConfig struct {
|
||||
AccessKeyID string `mapstructure:"access_key_id"`
|
||||
AccessKeySecret string `mapstructure:"access_key_secret"`
|
||||
EndpointURL string `mapstructure:"endpoint_url"`
|
||||
SignName string `mapstructure:"sign_name"`
|
||||
TemplateCode string `mapstructure:"template_code"`
|
||||
CodeLength int `mapstructure:"code_length"`
|
||||
ExpireTime time.Duration `mapstructure:"expire_time"`
|
||||
RateLimit SMSRateLimit `mapstructure:"rate_limit"`
|
||||
MockEnabled bool `mapstructure:"mock_enabled"` // 是否启用模拟短信服务
|
||||
}
|
||||
|
||||
// SMSRateLimit 短信限流配置
|
||||
type SMSRateLimit struct {
|
||||
DailyLimit int `mapstructure:"daily_limit"` // 每日发送限制
|
||||
HourlyLimit int `mapstructure:"hourly_limit"` // 每小时发送限制
|
||||
MinInterval time.Duration `mapstructure:"min_interval"` // 最小发送间隔
|
||||
}
|
||||
|
||||
// GetDSN 获取数据库DSN连接字符串
|
||||
func (d DatabaseConfig) GetDSN() string {
|
||||
return "host=" + d.Host +
|
||||
@@ -163,4 +186,4 @@ func (a AppConfig) IsDevelopment() bool {
|
||||
// IsStaging 检查是否为测试环境
|
||||
func (a AppConfig) IsStaging() bool {
|
||||
return a.Env == "staging"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user