179 lines
6.3 KiB
Go
179 lines
6.3 KiB
Go
package setting
|
||
|
||
// ServerSettingS 服务配置。时间字段单位为秒(int),避免 time.Duration 对整数配置按纳秒解析的歧义。
|
||
type ServerSettingS struct {
|
||
Domain string // 服务域名(用于 CORS 允许来源,如 test.com)
|
||
RunMode string
|
||
HttpPort string
|
||
ReadTimeout int // 秒
|
||
WriteTimeout int // 秒
|
||
}
|
||
|
||
type LogSettingS struct {
|
||
LogSavePath string
|
||
LogFileName string
|
||
LogFileExt string
|
||
MaxSize int
|
||
MaxBackups int
|
||
MaxAge int
|
||
LogLevel string
|
||
}
|
||
|
||
type MysqlSettingS struct {
|
||
UserName string
|
||
Password string
|
||
Host string
|
||
Port int
|
||
DBName string
|
||
MaxIdleConns int
|
||
MaxOpenConns int
|
||
ConnMaxLifeTime int
|
||
ConnMaxIdleTime int
|
||
}
|
||
|
||
type RedisSettingS struct {
|
||
Host string
|
||
Port int
|
||
Password string
|
||
DB int
|
||
PoolSize int
|
||
MaxIdleConns int
|
||
MinIdleConns int
|
||
MaxRetryBackoff int
|
||
MinRetryBackoff int
|
||
MaxRetries int
|
||
DialTimeout int
|
||
ReadTimeout int
|
||
WriteTimeout int
|
||
PoolTimeout int
|
||
}
|
||
|
||
type OtelSettingS struct {
|
||
Enabled bool
|
||
ServiceName string
|
||
ServiceVersion string
|
||
Environment string
|
||
ExporterEndpoint string
|
||
Insecure bool
|
||
SamplerRatio float64
|
||
}
|
||
|
||
type JWTSettingS struct {
|
||
SecretKey string
|
||
Issuer string
|
||
AccessTokenExpire int // 秒
|
||
RefreshTokenExpire int // 秒
|
||
}
|
||
|
||
type UploadSettingS struct {
|
||
TmpSavePath string
|
||
MaxSizeMB int
|
||
AllowedExtensions []string
|
||
}
|
||
|
||
type CosSettingS struct {
|
||
CosSecretID string
|
||
CosSecretKey string
|
||
CosUploadDomain string
|
||
CosDownloadDomain string
|
||
CdnDownloadSecretKey string
|
||
}
|
||
|
||
type TokenhubSettingS struct {
|
||
APIKey string
|
||
Model string
|
||
}
|
||
|
||
type MattingModelSettingS struct {
|
||
Host string
|
||
Port int
|
||
MaxRetry int
|
||
}
|
||
|
||
type ClassificationModelSettingS struct {
|
||
Host string
|
||
Port int
|
||
MaxRetry int
|
||
}
|
||
|
||
// WechatMiniSettingS 微信小程序配置(用于 code2session 登录)。
|
||
type WechatMiniSettingS struct {
|
||
AppID string
|
||
AppSecret string
|
||
}
|
||
|
||
// WechatPaySettingS 微信支付 V3 商户配置。
|
||
type WechatPaySettingS struct {
|
||
Enable bool // 是否启用微信支付;未开通时置 false,支付下单返回「未配置」
|
||
AppID string // 小程序 AppID(下单/调起支付使用)
|
||
MchID string // 商户号
|
||
APIv3Key string // APIv3 密钥(32 字节,用于回调解密)
|
||
SerialNo string // 商户证书序列号
|
||
PrivateKeyPath string // 商户 API 私钥 PEM 文件路径
|
||
NotifyURL string // 支付结果回调地址
|
||
RefundNotifyURL string // 退款结果回调地址
|
||
}
|
||
|
||
// VirtualPaySettingS 微信小程序虚拟支付(XPay)配置。
|
||
// 虚拟支付与普通微信支付为独立商户号、独立结算,配置项在 MP 后台「虚拟支付 → 基本配置」获取。
|
||
type VirtualPaySettingS struct {
|
||
OfferID string // 虚拟支付 OfferID(AppID)
|
||
EnvAppKey string // 现网 AppKey(env=0)
|
||
SandboxAppKey string // 沙箱 AppKey(env=1,iOS 不支持沙箱,默认不启用)
|
||
Token string // 消息推送验签 Token(配置回调地址时自定义)
|
||
EncodingAESKey string // 消息加解密密钥(43 位;填了即启用「安全模式」纯密文收发,留空为明文模式)
|
||
Enable bool // 是否启用虚拟支付;未开通时置 false,虚拟商品下单返回「虚拟支付未开通」
|
||
}
|
||
|
||
// UserDefaultQuotaSettingS 新用户注册时初始化的免费额度配置。
|
||
// 使用指针类型以区分「未配置」与「显式配置为 0」:
|
||
// - nil:该项未配置(或整段缺失),由 service 层回落内置默认常量;
|
||
// - 非 nil:以配置值为准,允许为 0(表示不赠送该类免费额度);
|
||
// - 负数:视为非法配置,回落内置默认常量。
|
||
type UserDefaultQuotaSettingS struct {
|
||
Cos *int64 // 免费上传额度(永久,不每天重置)
|
||
AI *int64 // 免费 AI 推荐额度(每日,每天 0 点重置)
|
||
OutfitShare *int64 // 免费社区分享额度(每日,每天 0 点重置)
|
||
ClosetShare *int64 // 免费衣柜分享额度(每日,每天 0 点重置;0 表示不赠送)
|
||
// [已废弃] 体验会员天数已迁至 NewUserGift.GiftVIPDay。
|
||
// 保留此字段仅为兼容旧配置:新位置未配置时回落读这里。
|
||
GiftVIPDay *int64
|
||
}
|
||
|
||
// NewUserGiftSettingS 新用户注册赠送的体验会员及其额度配置。
|
||
//
|
||
// 与 UserDefaultQuota 的区别:
|
||
// - UserDefaultQuota 是「免费额度」,所有用户长期享有,不依赖会员身份;
|
||
// - 本段是「注册赠送」,其中额度以体验会员凭证(source=4)发放,有效期是
|
||
// 「注册时刻 + 体验天数」这个固定值,不随后续续费延长(否则用户充值后会把
|
||
// 体验额度一直「继承」下去);因此仅在 GiftVIPDay > 0 时才发放。
|
||
//
|
||
// 指针语义同 UserDefaultQuotaSettingS:nil 回落内置默认,显式 0 表示不赠送,负数视为非法。
|
||
type NewUserGiftSettingS struct {
|
||
GiftVIPDay *int64 // 赠送的体验会员天数(vip_type=4);0 表示不赠送体验会员
|
||
Cos *int64 // 体验会员赠送的上传额度
|
||
AI *int64 // 体验会员赠送的 AI 推荐额度
|
||
OutfitShare *int64 // 体验会员赠送的社区分享额度
|
||
ClosetShare *int64 // 体验会员赠送的衣柜分享额度
|
||
}
|
||
|
||
// AdRewardSettingS 广告激励额度配置。
|
||
// 金额为服务端固定值,前端不传金额,从根源杜绝刷额度;各类型金额使用指针以区分
|
||
// 「未配置/显式 0」,nil 或非正数表示不发放该类型激励。
|
||
type AdRewardSettingS struct {
|
||
Enable bool // 是否开启广告激励;关闭时接口返回「广告激励未开启」
|
||
Cos *int64 // 广告激励赠送的 Cos 上传额度(固定值)
|
||
AI *int64 // 广告激励赠送的 AI 推荐额度(固定值)
|
||
OutfitShare *int64 // 广告激励赠送的社区分享额度(固定值)
|
||
ClosetShare *int64 // 广告激励赠送的衣柜分享额度(固定值)
|
||
MaxClaimsPerDay int // 单用户、单类型每天最多领取次数;未配置默认 1
|
||
}
|
||
|
||
func (s *Setting) ReadSection(k string, v any) error {
|
||
err := s.vp.UnmarshalKey(k, v)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
return nil
|
||
}
|