2024-06-17 14:18:39 +08:00
|
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/BurntSushi/toml"
|
|
|
|
|
"github.com/qit-team/snow-core/config"
|
|
|
|
|
"os"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
ProdEnv = "production" //线上环境
|
|
|
|
|
BetaEnv = "beta" //beta环境
|
|
|
|
|
DevEnv = "develop" //开发环境
|
|
|
|
|
LocalEnv = "local" //本地环境
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var srvConf *Config
|
|
|
|
|
|
|
|
|
|
// ------------------------配置文件解析
|
|
|
|
|
type Config struct {
|
|
|
|
|
ServiceName string `toml:"ServiceName"`
|
|
|
|
|
Env string `toml:"Env"`
|
|
|
|
|
Debug bool `toml:"Debug"`
|
|
|
|
|
PrometheusCollectEnable bool `toml:"PrometheusCollectEnable"`
|
|
|
|
|
SkyWalkingOapServer string `toml:"SkyWalkingOapServer"`
|
|
|
|
|
Log config.LogConfig `toml:"Log"`
|
|
|
|
|
Redis config.RedisConfig `toml:"Redis"`
|
|
|
|
|
Mns config.MnsConfig `toml:"AliMns"`
|
|
|
|
|
Db config.DbConfig `toml:"Db"`
|
|
|
|
|
Api config.ApiConfig `toml:"Api"`
|
|
|
|
|
Admin config.ApiConfig `toml:"Admin"`
|
|
|
|
|
Nacos Nacos `toml:"Nacas"`
|
|
|
|
|
Rpc Rpc `toml:"Rpc"`
|
|
|
|
|
AppKey string `toml:"AppKey"`
|
|
|
|
|
Sm2 Sm2 `toml:"Sm2"`
|
|
|
|
|
OpenApiMarketConfig MarketConfig `toml:"MarketConfig"`
|
|
|
|
|
OpenApi OpenApi `toml:"OpenApi"`
|
|
|
|
|
Jwt Jwt `toml:"Jwt"`
|
|
|
|
|
AliOss AliOss `toml:"AliOss"`
|
2024-06-19 18:32:34 +08:00
|
|
|
|
YouChu YouChuConfig `toml:"YouChu"`
|
2024-07-10 10:11:32 +08:00
|
|
|
|
YouChuCallBack YouChuCallBack `toml:"YouChuCallBack"`
|
2024-08-21 14:30:20 +08:00
|
|
|
|
SmFourKey string `toml:"SmFourKey"`
|
2024-06-17 16:29:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-19 18:32:34 +08:00
|
|
|
|
type YouChuConfig struct {
|
2024-06-25 10:12:48 +08:00
|
|
|
|
LoginHost string //登录地址
|
|
|
|
|
OrderHost string //订单地址
|
2024-06-19 18:32:34 +08:00
|
|
|
|
NotifyUrl string
|
2024-06-24 11:44:38 +08:00
|
|
|
|
MilkUrl string //奶茶专区跳转链接
|
|
|
|
|
VoucherUrl string //代金券链接
|
2024-06-19 18:32:34 +08:00
|
|
|
|
MerchantId string //合作方编号
|
|
|
|
|
MchtNo string //上单商户号
|
|
|
|
|
AppID string //appid
|
|
|
|
|
SopPublicKey string //服开公钥
|
|
|
|
|
SopPrivateKey string //服开私钥
|
2024-08-29 22:21:12 +08:00
|
|
|
|
FileHost string
|
2024-06-17 14:18:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 10:11:32 +08:00
|
|
|
|
type YouChuCallBack struct {
|
|
|
|
|
MerchantId string //合作方编号
|
|
|
|
|
SopPublicKey string //服开公钥
|
|
|
|
|
PrivateKey string
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 14:18:39 +08:00
|
|
|
|
type AliOss struct {
|
|
|
|
|
AccessKey string
|
|
|
|
|
AccessKeySecret string
|
|
|
|
|
EndPoint string
|
|
|
|
|
BucKet string
|
|
|
|
|
Domain string
|
|
|
|
|
Dir string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Jwt struct {
|
|
|
|
|
SecretKey string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type OpenApi struct {
|
|
|
|
|
MerchantId string
|
|
|
|
|
SecretKey string
|
|
|
|
|
IsProd bool
|
|
|
|
|
NotifyUrl string
|
|
|
|
|
TimeOut int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MarketConfig struct {
|
|
|
|
|
AppId string `json:"app_id"` //APP ID
|
|
|
|
|
Sign string `json:"sign"` //签名
|
|
|
|
|
ReqCode string `json:"req_code"` //固定值:voucher.create
|
|
|
|
|
MemId string `json:"mem_id"` //商户号
|
|
|
|
|
PosId string `json:"pos_id"` //商户方平台号
|
|
|
|
|
Host string `json:"-"`
|
|
|
|
|
SecretKey string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Sm2 struct {
|
|
|
|
|
PublicKey string
|
|
|
|
|
PrivateKey string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Rpc struct {
|
|
|
|
|
User string
|
|
|
|
|
}
|
|
|
|
|
type Nacos struct {
|
|
|
|
|
Url string
|
|
|
|
|
Port int64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newConfig() *Config {
|
|
|
|
|
return new(Config)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ------------------------ 加载配置 ------------------------//
|
|
|
|
|
func Load(path string) (*Config, error) {
|
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
conf := newConfig()
|
|
|
|
|
if _, err := toml.DecodeFile(path, conf); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
srvConf = conf
|
|
|
|
|
return conf, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 当前配置
|
|
|
|
|
func GetConf() *Config {
|
|
|
|
|
return srvConf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否调试模式
|
|
|
|
|
func IsDebug() bool {
|
|
|
|
|
return srvConf.Debug
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 当前环境,默认本地开发
|
|
|
|
|
func GetEnv() string {
|
|
|
|
|
if srvConf.Env == "" {
|
|
|
|
|
return LocalEnv
|
|
|
|
|
}
|
|
|
|
|
return srvConf.Env
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否当前环境
|
|
|
|
|
func IsEnvEqual(env string) bool {
|
|
|
|
|
return GetEnv() == env
|
|
|
|
|
}
|