refactor: 重构抽奖逻辑以支持可验证凭据 feat(redis): 集成Redis客户端并添加配置支持 fix: 修复订单取消时的优惠券和库存处理逻辑 docs: 添加对对碰游戏前端对接指南和示例JSON test: 添加对对碰游戏模拟测试和验证逻辑
143 lines
3.9 KiB
Go
143 lines
3.9 KiB
Go
package configs
|
|
|
|
import (
|
|
"bytes"
|
|
_ "embed"
|
|
"io"
|
|
"os"
|
|
|
|
"bindbox-game/internal/pkg/env"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var config = new(Config)
|
|
|
|
type Config struct {
|
|
MySQL struct {
|
|
Read struct {
|
|
Addr string `mapstructure:"addr" toml:"addr"`
|
|
User string `mapstructure:"user" toml:"user"`
|
|
Pass string `mapstructure:"pass" toml:"pass"`
|
|
Name string `mapstructure:"name" toml:"name"`
|
|
} `mapstructure:"read" toml:"read"`
|
|
Write struct {
|
|
Addr string `mapstructure:"addr" toml:"addr"`
|
|
User string `mapstructure:"user" toml:"user"`
|
|
Pass string `mapstructure:"pass" toml:"pass"`
|
|
Name string `mapstructure:"name" toml:"name"`
|
|
} `mapstructure:"write" toml:"write"`
|
|
} `mapstructure:"mysql" toml:"mysql"`
|
|
|
|
Redis struct {
|
|
Addr string `mapstructure:"addr" toml:"addr"`
|
|
Pass string `mapstructure:"pass" toml:"pass"`
|
|
DB int `mapstructure:"db" toml:"db"`
|
|
} `mapstructure:"redis" toml:"redis"`
|
|
|
|
JWT struct {
|
|
AdminSecret string `mapstructure:"admin_secret" toml:"admin_secret"`
|
|
PatientSecret string `mapstructure:"patient_secret" toml:"patient_secret"`
|
|
DoctorSecret string `mapstructure:"doctor_secret" toml:"doctor_secret"`
|
|
} `mapstructure:"jwt" toml:"jwt"`
|
|
|
|
Language struct {
|
|
Local string `mapstructure:"local" toml:"local"`
|
|
} `mapstructure:"language" toml:"language"`
|
|
|
|
Wechat struct {
|
|
AppID string `mapstructure:"app_id" toml:"app_id"`
|
|
AppSecret string `mapstructure:"app_secret" toml:"app_secret"`
|
|
LotteryResultTemplateID string `mapstructure:"lottery_result_template_id" toml:"lottery_result_template_id"`
|
|
} `mapstructure:"wechat" toml:"wechat"`
|
|
|
|
WechatPay struct {
|
|
MchID string `mapstructure:"mchid" toml:"mchid"`
|
|
SerialNo string `mapstructure:"serial_no" toml:"serial_no"`
|
|
PrivateKeyPath string `mapstructure:"private_key_path" toml:"private_key_path"`
|
|
ApiV3Key string `mapstructure:"api_v3_key" toml:"api_v3_key"`
|
|
NotifyURL string `mapstructure:"notify_url" toml:"notify_url"`
|
|
PublicKeyID string `mapstructure:"public_key_id" toml:"public_key_id"`
|
|
PublicKeyPath string `mapstructure:"public_key_path" toml:"public_key_path"`
|
|
} `mapstructure:"wechatpay" toml:"wechatpay"`
|
|
|
|
COS struct {
|
|
Bucket string `mapstructure:"bucket" toml:"bucket"`
|
|
Region string `mapstructure:"region" toml:"region"`
|
|
SecretID string `mapstructure:"secret_id" toml:"secret_id"`
|
|
SecretKey string `mapstructure:"secret_key" toml:"secret_key"`
|
|
BaseURL string `mapstructure:"base_url" toml:"base_url"`
|
|
} `mapstructure:"cos" toml:"cos"`
|
|
|
|
Random struct {
|
|
CommitMasterKey string `mapstructure:"commit_master_key" toml:"commit_master_key"`
|
|
} `mapstructure:"random" toml:"random"`
|
|
}
|
|
|
|
var (
|
|
//go:embed dev_configs.toml
|
|
devConfigs []byte
|
|
|
|
//go:embed fat_configs.toml
|
|
fatConfigs []byte
|
|
|
|
//go:embed uat_configs.toml
|
|
uatConfigs []byte
|
|
|
|
//go:embed pro_configs.toml
|
|
proConfigs []byte
|
|
)
|
|
|
|
func init() {
|
|
var r io.Reader
|
|
|
|
switch env.Active().Value() {
|
|
case "dev":
|
|
r = bytes.NewReader(devConfigs)
|
|
case "fat":
|
|
r = bytes.NewReader(fatConfigs)
|
|
case "uat":
|
|
r = bytes.NewReader(uatConfigs)
|
|
case "pro":
|
|
r = bytes.NewReader(proConfigs)
|
|
default:
|
|
r = bytes.NewReader(fatConfigs)
|
|
}
|
|
|
|
viper.SetConfigType("toml")
|
|
|
|
if err := viper.ReadConfig(r); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if err := viper.Unmarshal(config); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
if v := os.Getenv("WECHAT_MCHID"); v != "" {
|
|
config.WechatPay.MchID = v
|
|
}
|
|
if v := os.Getenv("WECHAT_SERIAL_NO"); v != "" {
|
|
config.WechatPay.SerialNo = v
|
|
}
|
|
if v := os.Getenv("WECHAT_PRIVATE_KEY_PATH"); v != "" {
|
|
config.WechatPay.PrivateKeyPath = v
|
|
}
|
|
if v := os.Getenv("WECHAT_API_V3_KEY"); v != "" {
|
|
config.WechatPay.ApiV3Key = v
|
|
}
|
|
if v := os.Getenv("WECHAT_NOTIFY_URL"); v != "" {
|
|
config.WechatPay.NotifyURL = v
|
|
}
|
|
if v := os.Getenv("WECHAT_PUBLIC_KEY_ID"); v != "" {
|
|
config.WechatPay.PublicKeyID = v
|
|
}
|
|
if v := os.Getenv("WECHAT_PUBLIC_KEY_PATH"); v != "" {
|
|
config.WechatPay.PublicKeyPath = v
|
|
}
|
|
}
|
|
|
|
func Get() Config {
|
|
return *config
|
|
}
|