chore: apply task changes

This commit is contained in:
2026-01-30 17:05:44 +08:00
parent 4856a88d41
commit 3f63fffbb1
22 changed files with 4696 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ type Config struct {
JWT JWTConfig `mapstructure:"jwt"`
DefaultAdmin DefaultAdminConfig `mapstructure:"default_admin"`
Storage StorageConfig `mapstructure:"storage"`
Gateway GatewayConfig `mapstructure:"gateway"`
}
// ServerConfig HTTP 服务器配置
@@ -130,6 +131,14 @@ type StorageConfig struct {
TempDir string `mapstructure:"temp_dir"` // 临时文件目录
}
// GatewayConfig Gateway 服务配置
type GatewayConfig struct {
BaseURL string `mapstructure:"base_url"` // Gateway API 基础 URL
AppID string `mapstructure:"app_id"` // 应用 ID
AppSecret string `mapstructure:"app_secret"` // 应用密钥
Timeout int `mapstructure:"timeout"` // 超时时间(秒)
}
// S3Config S3 兼容存储配置
type S3Config struct {
Endpoint string `mapstructure:"endpoint"` // 服务端点http://obs-helf.cucloud.cn
@@ -270,6 +279,22 @@ func (c *Config) Validate() error {
return fmt.Errorf("invalid configuration: jwt.refresh_token_ttl: duration out of range (current value: %s, expected: 24h-720h)", c.JWT.RefreshTokenTTL)
}
// Gateway 验证(可选,配置 BaseURL 时才验证其他字段)
if c.Gateway.BaseURL != "" {
if !strings.HasPrefix(c.Gateway.BaseURL, "http://") && !strings.HasPrefix(c.Gateway.BaseURL, "https://") {
return fmt.Errorf("invalid configuration: gateway.base_url: must start with http:// or https:// (current value: %s)", c.Gateway.BaseURL)
}
if c.Gateway.AppID == "" {
return fmt.Errorf("invalid configuration: gateway.app_id: must be non-empty when base_url is configured")
}
if c.Gateway.AppSecret == "" {
return fmt.Errorf("invalid configuration: gateway.app_secret: must be non-empty when base_url is configured")
}
if c.Gateway.Timeout < 5 || c.Gateway.Timeout > 300 {
return fmt.Errorf("invalid configuration: gateway.timeout: timeout out of range (current value: %d, expected: 5-300 seconds)", c.Gateway.Timeout)
}
}
return nil
}