chore: apply task changes
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -104,3 +104,10 @@ default_admin:
|
||||
username: ""
|
||||
password: ""
|
||||
phone: ""
|
||||
|
||||
# Gateway 服务配置
|
||||
gateway:
|
||||
base_url: "https://lplan.whjhft.com/openapi"
|
||||
app_id: "60bgt1X8i7AvXqkd"
|
||||
app_secret: "BZeQttaZQt0i73moF"
|
||||
timeout: 30
|
||||
|
||||
@@ -92,6 +92,13 @@ const (
|
||||
CodeCarrierNotFound = 1100 // 运营商不存在
|
||||
CodeCarrierCodeExists = 1101 // 运营商编码已存在
|
||||
|
||||
// Gateway 相关错误 (1110-1119)
|
||||
CodeGatewayError = 1110 // Gateway 通用错误
|
||||
CodeGatewayEncryptError = 1111 // 数据加密失败
|
||||
CodeGatewaySignError = 1112 // 签名生成失败
|
||||
CodeGatewayTimeout = 1113 // 请求超时
|
||||
CodeGatewayInvalidResp = 1114 // 响应格式错误
|
||||
|
||||
// 服务端错误 (2000-2999) -> 5xx HTTP 状态码
|
||||
CodeInternalError = 2001 // 内部服务器错误
|
||||
CodeDatabaseError = 2002 // 数据库错误
|
||||
@@ -174,6 +181,11 @@ var allErrorCodes = []int{
|
||||
CodeStorageInvalidFileType,
|
||||
CodeCarrierNotFound,
|
||||
CodeCarrierCodeExists,
|
||||
CodeGatewayError,
|
||||
CodeGatewayEncryptError,
|
||||
CodeGatewaySignError,
|
||||
CodeGatewayTimeout,
|
||||
CodeGatewayInvalidResp,
|
||||
CodeInternalError,
|
||||
CodeDatabaseError,
|
||||
CodeRedisError,
|
||||
@@ -258,6 +270,11 @@ var errorMessages = map[int]string{
|
||||
CodeStorageInvalidFileType: "不支持的文件类型",
|
||||
CodeCarrierNotFound: "运营商不存在",
|
||||
CodeCarrierCodeExists: "运营商编码已存在",
|
||||
CodeGatewayError: "Gateway 请求失败",
|
||||
CodeGatewayEncryptError: "数据加密失败",
|
||||
CodeGatewaySignError: "签名生成失败",
|
||||
CodeGatewayTimeout: "Gateway 请求超时",
|
||||
CodeGatewayInvalidResp: "Gateway 响应格式错误",
|
||||
CodeInvalidCredentials: "用户名或密码错误",
|
||||
CodeAccountLocked: "账号已锁定",
|
||||
CodePasswordExpired: "密码已过期",
|
||||
|
||||
Reference in New Issue
Block a user