Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 25s
feat(admin): 新增工会管理功能 feat(activity): 添加活动管理相关服务 feat(user): 实现用户道具卡和积分管理 feat(guild): 新增工会成员管理功能 fix: 修复数据库连接配置 fix: 修正jwtoken导入路径 fix: 解决端口冲突问题 style: 统一代码格式和注释风格 style: 更新项目常量命名 docs: 添加项目框架和开发规范文档 docs: 更新接口文档注释 chore: 移除无用代码和文件 chore: 更新Makefile和配置文件 chore: 清理日志文件 test: 添加道具卡测试脚本
99 lines
2.3 KiB
Go
99 lines
2.3 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"`
|
|
}
|
|
|
|
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
|
|
}
|