bindbox-game/configs/configs.go
邹方成 81e2fb5a75
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 41s
feat(activity): 实现抽奖随机承诺与验证功能
新增随机种子生成与验证逻辑,包括:
1. 添加随机承诺生成接口
2. 实现抽奖执行与验证流程
3. 新增批量用户创建与删除功能
4. 添加抽奖收据记录表
5. 完善配置管理与错误码

新增测试用例验证随机算法正确性
2025-11-15 20:39:13 +08:00

103 lines
2.4 KiB
Go

package configs
import (
"bytes"
_ "embed"
"io"
"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"`
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"`
} `mapstructure:"wechat" toml:"wechat"`
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)
}
}
func Get() Config {
return *config
}