first commit
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
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(配置回调地址时自定义)
|
||||
Enable bool // 是否启用虚拟支付;未开通时置 false,虚拟商品下单返回「虚拟支付未开通」
|
||||
}
|
||||
|
||||
// UserDefaultQuotaSettingS 新用户注册时初始化的免费额度与赠送会员天数配置。
|
||||
// 使用指针类型以区分「未配置」与「显式配置为 0」:
|
||||
// - nil:该项未配置(或整段缺失),由 service 层回落内置默认常量;
|
||||
// - 非 nil:以配置值为准,允许为 0(额度类表示不赠送,GiftVIPDay 表示不赠送体验会员);
|
||||
// - 负数:视为非法配置,回落内置默认常量。
|
||||
type UserDefaultQuotaSettingS struct {
|
||||
Cos *int64 // 免费上传额度(永久,不每天重置)
|
||||
AI *int64 // 免费 AI 推荐额度(每日,每天 0 点重置)
|
||||
OutfitShare *int64 // 免费社区分享额度(每日,每天 0 点重置)
|
||||
ClosetShare *int64 // 免费衣柜分享额度(每日,每天 0 点重置;0 表示不赠送)
|
||||
GiftVIPDay *int64 // 注册赠送的体验会员天数(vip_type=4,0 表示不赠送)
|
||||
}
|
||||
|
||||
// AdRewardSettingS 广告激励额度配置。
|
||||
// 金额为服务端固定值,前端不传金额,从根源杜绝刷额度;各类型金额使用指针以区分
|
||||
// 「未配置/显式 0」,nil 或非正数表示不发放该类型激励。
|
||||
type AdRewardSettingS struct {
|
||||
Enable bool // 是否开启广告激励;关闭时接口返回「广告激励未开启」
|
||||
Cos *int64 // 广告激励赠送的 Cos 上传额度(固定值)
|
||||
AI *int64 // 广告激励赠送的 AI 推荐额度(固定值)
|
||||
OutfitShare *int64 // 广告激励赠送的社区分享额度(固定值)
|
||||
ClosetShare *int64 // 广告激励赠送的衣柜分享额度(固定值)
|
||||
}
|
||||
|
||||
func (s *Setting) ReadSection(k string, v any) error {
|
||||
err := s.vp.UnmarshalKey(k, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package setting
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// Setting 封装 viper 配置读取能力。
|
||||
type Setting struct {
|
||||
vp *viper.Viper
|
||||
}
|
||||
|
||||
// NewSetting 初始化配置读取器,仅从 configs/config.yaml 读取配置。
|
||||
// 所有配置项一律在配置文件中直接填写,不支持环境变量覆盖。
|
||||
func NewSetting() (*Setting, error) {
|
||||
vp := viper.New()
|
||||
vp.AddConfigPath("configs/")
|
||||
vp.SetConfigName("config")
|
||||
vp.SetConfigType("yaml")
|
||||
if err := vp.ReadInConfig(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Setting{vp: vp}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user