package config import ( "time" ) // Config 应用程序总配置 type Config struct { Server ServerConfig `mapstructure:"server"` Database DatabaseConfig `mapstructure:"database"` Redis RedisConfig `mapstructure:"redis"` Cache CacheConfig `mapstructure:"cache"` Logger LoggerConfig `mapstructure:"logger"` JWT JWTConfig `mapstructure:"jwt"` API APIConfig `mapstructure:"api"` SMS SMSConfig `mapstructure:"sms"` Storage StorageConfig `mapstructure:"storage"` OCR OCRConfig `mapstructure:"ocr"` RateLimit RateLimitConfig `mapstructure:"ratelimit"` Monitoring MonitoringConfig `mapstructure:"monitoring"` Health HealthConfig `mapstructure:"health"` Resilience ResilienceConfig `mapstructure:"resilience"` Development DevelopmentConfig `mapstructure:"development"` App AppConfig `mapstructure:"app"` WechatWork WechatWorkConfig `mapstructure:"wechat_work"` Esign EsignConfig `mapstructure:"esign"` Wallet WalletConfig `mapstructure:"wallet"` WestDex WestDexConfig `mapstructure:"westdex"` AliPay AliPayConfig `mapstructure:"alipay"` Recharge RechargeConfig `mapstructure:"recharge"` Yushan YushanConfig `mapstructure:"yushan"` Domain DomainConfig `mapstructure:"domain"` } // ServerConfig HTTP服务器配置 type ServerConfig struct { Port string `mapstructure:"port"` Mode string `mapstructure:"mode"` Host string `mapstructure:"host"` ReadTimeout time.Duration `mapstructure:"read_timeout"` WriteTimeout time.Duration `mapstructure:"write_timeout"` IdleTimeout time.Duration `mapstructure:"idle_timeout"` } // DatabaseConfig 数据库配置 type DatabaseConfig struct { Host string `mapstructure:"host"` Port string `mapstructure:"port"` User string `mapstructure:"user"` Password string `mapstructure:"password"` Name string `mapstructure:"name"` SSLMode string `mapstructure:"sslmode"` Timezone string `mapstructure:"timezone"` 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配置 type RedisConfig struct { Host string `mapstructure:"host"` Port string `mapstructure:"port"` Password string `mapstructure:"password"` DB int `mapstructure:"db"` PoolSize int `mapstructure:"pool_size"` MinIdleConns int `mapstructure:"min_idle_conns"` MaxRetries int `mapstructure:"max_retries"` DialTimeout time.Duration `mapstructure:"dial_timeout"` ReadTimeout time.Duration `mapstructure:"read_timeout"` WriteTimeout time.Duration `mapstructure:"write_timeout"` } // CacheConfig 缓存配置 type CacheConfig struct { DefaultTTL time.Duration `mapstructure:"default_ttl"` CleanupInterval time.Duration `mapstructure:"cleanup_interval"` MaxSize int `mapstructure:"max_size"` } // 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"` UseColor bool `mapstructure:"use_color"` } // JWTConfig JWT配置 type JWTConfig struct { Secret string `mapstructure:"secret"` ExpiresIn time.Duration `mapstructure:"expires_in"` RefreshExpiresIn time.Duration `mapstructure:"refresh_expires_in"` } // RateLimitConfig 限流配置 type RateLimitConfig struct { Requests int `mapstructure:"requests"` Window time.Duration `mapstructure:"window"` Burst int `mapstructure:"burst"` } // MonitoringConfig 监控配置 type MonitoringConfig struct { MetricsEnabled bool `mapstructure:"metrics_enabled"` MetricsPort string `mapstructure:"metrics_port"` TracingEnabled bool `mapstructure:"tracing_enabled"` TracingEndpoint string `mapstructure:"tracing_endpoint"` SampleRate float64 `mapstructure:"sample_rate"` } // HealthConfig 健康检查配置 type HealthConfig struct { Enabled bool `mapstructure:"enabled"` Interval time.Duration `mapstructure:"interval"` Timeout time.Duration `mapstructure:"timeout"` } // ResilienceConfig 容错配置 type ResilienceConfig struct { CircuitBreakerEnabled bool `mapstructure:"circuit_breaker_enabled"` CircuitBreakerThreshold int `mapstructure:"circuit_breaker_threshold"` CircuitBreakerTimeout time.Duration `mapstructure:"circuit_breaker_timeout"` RetryMaxAttempts int `mapstructure:"retry_max_attempts"` RetryInitialDelay time.Duration `mapstructure:"retry_initial_delay"` RetryMaxDelay time.Duration `mapstructure:"retry_max_delay"` } // 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"` } // AppConfig 应用程序配置 type AppConfig struct { Name string `mapstructure:"name"` Version string `mapstructure:"version"` Env string `mapstructure:"env"` } // APIConfig API配置 type APIConfig struct { Domain string `mapstructure:"domain"` } // 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 + " user=" + d.User + " password=" + d.Password + " dbname=" + d.Name + " port=" + d.Port + " sslmode=" + d.SSLMode + " TimeZone=" + d.Timezone } // GetRedisAddr 获取Redis地址 func (r RedisConfig) GetRedisAddr() string { return r.Host + ":" + r.Port } // IsProduction 检查是否为生产环境 func (a AppConfig) IsProduction() bool { return a.Env == "production" } // IsDevelopment 检查是否为开发环境 func (a AppConfig) IsDevelopment() bool { return a.Env == "development" } // IsStaging 检查是否为测试环境 func (a AppConfig) IsStaging() bool { return a.Env == "staging" } // WechatWorkConfig 企业微信配置 type WechatWorkConfig struct { WebhookURL string `mapstructure:"webhook_url"` Secret string `mapstructure:"secret"` } // StorageConfig 存储服务配置 type StorageConfig struct { AccessKey string `mapstructure:"access_key"` SecretKey string `mapstructure:"secret_key"` Bucket string `mapstructure:"bucket"` Domain string `mapstructure:"domain"` } // OCRConfig OCR服务配置 type OCRConfig struct { APIKey string `mapstructure:"api_key"` SecretKey string `mapstructure:"secret_key"` } // EsignConfig e签宝配置 type EsignConfig struct { AppID string `mapstructure:"app_id"` // 应用ID AppSecret string `mapstructure:"app_secret"` // 应用密钥 ServerURL string `mapstructure:"server_url"` // 服务器URL TemplateID string `mapstructure:"template_id"` // 模板ID Contract ContractConfig `mapstructure:"contract"` // 合同配置 Auth AuthConfig `mapstructure:"auth"` // 认证配置 Sign SignConfig `mapstructure:"sign"` // 签署配置 } // ContractConfig 合同配置 type ContractConfig struct { Name string `mapstructure:"name"` // 合同名称 ExpireDays int `mapstructure:"expire_days"` // 签署链接过期天数 RetryCount int `mapstructure:"retry_count"` // 重试次数 } // AuthConfig 认证配置 type AuthConfig struct { OrgAuthModes []string `mapstructure:"org_auth_modes"` // 机构可用认证模式 DefaultAuthMode string `mapstructure:"default_auth_mode"` // 默认认证模式 PsnAuthModes []string `mapstructure:"psn_auth_modes"` // 个人可用认证模式 WillingnessAuthModes []string `mapstructure:"willingness_auth_modes"` // 意愿认证模式 RedirectURL string `mapstructure:"redirect_url"` // 重定向URL } // SignConfig 签署配置 type SignConfig struct { AutoFinish bool `mapstructure:"auto_finish"` // 是否自动完结 SignFieldStyle int `mapstructure:"sign_field_style"` // 签署区样式 ClientType string `mapstructure:"client_type"` // 客户端类型 RedirectURL string `mapstructure:"redirect_url"` // 重定向URL } // WalletConfig 钱包配置 type WalletConfig struct { DefaultCreditLimit float64 `mapstructure:"default_credit_limit"` } // WestDexConfig WestDex配置 type WestDexConfig struct { URL string `mapstructure:"url"` Key string `mapstructure:"key"` SecretId string `mapstructure:"secret_id"` SecretSecondId string `mapstructure:"secret_second_id"` } // AliPayConfig 支付宝配置 type AliPayConfig struct { AppID string `mapstructure:"app_id"` PrivateKey string `mapstructure:"private_key"` AlipayPublicKey string `mapstructure:"alipay_public_key"` IsProduction bool `mapstructure:"is_production"` NotifyURL string `mapstructure:"notify_url"` ReturnURL string `mapstructure:"return_url"` } // RechargeConfig 充值配置 type RechargeConfig struct { MinAmount string `mapstructure:"min_amount"` // 最低充值金额 MaxAmount string `mapstructure:"max_amount"` // 最高充值金额 } // YushanConfig 羽山配置 type YushanConfig struct { URL string `mapstructure:"url"` APIKey string `mapstructure:"api_key"` AcctID string `mapstructure:"acct_id"` } // DomainConfig 域名配置 type DomainConfig struct { API string `mapstructure:"api"` // API域名 }