52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
// Package config 沿用 sample/server 的 BSM 配置加载与校验方式。
|
|
package config
|
|
|
|
import (
|
|
"net"
|
|
"net/url"
|
|
|
|
"git.apinb.com/bsm-sdk/core/conf"
|
|
)
|
|
|
|
// Spec 是 Platform API 的运行配置。
|
|
var Spec SrvConfig
|
|
|
|
// GlobalConfig 保存多个管理端共用的运行参数。
|
|
type GlobalConfig struct {
|
|
UserRegisterURL string `yaml:"UserRegisterURL"`
|
|
ManualRechargeMaxAmount int64 `yaml:"ManualRechargeMaxAmount"`
|
|
}
|
|
|
|
// WalletConfig 是平台既有钱包逻辑的内部兼容视图,值由 Global 注入。
|
|
type WalletConfig struct {
|
|
ManualRechargeMaxAmount int64 `yaml:"-"`
|
|
}
|
|
|
|
// SrvConfig 与 sample/server 配置结构保持一致。
|
|
type SrvConfig struct {
|
|
conf.Base `yaml:",inline"`
|
|
Databases *conf.DBConf `yaml:"Databases"`
|
|
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
|
|
Apm *conf.ApmConf `yaml:"APM"`
|
|
Global GlobalConfig `yaml:"Global"`
|
|
Wallet WalletConfig `yaml:"-"`
|
|
}
|
|
|
|
// New 初始化 BSM 配置并校验服务监听地址。
|
|
func New(srvKey string) {
|
|
conf.New(srvKey, &Spec)
|
|
Spec.Port = conf.CheckPort(Spec.Port)
|
|
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
|
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
|
conf.NotNil(Spec.Service, Spec.Cache)
|
|
if Spec.Global.ManualRechargeMaxAmount <= 0 {
|
|
panic("Global.ManualRechargeMaxAmount must be greater than zero")
|
|
}
|
|
Spec.Wallet.ManualRechargeMaxAmount = Spec.Global.ManualRechargeMaxAmount
|
|
registerURL, err := url.ParseRequestURI(Spec.Global.UserRegisterURL)
|
|
if err != nil || (registerURL.Scheme != "http" && registerURL.Scheme != "https") || registerURL.Host == "" {
|
|
panic("Global.UserRegisterURL must be a valid HTTP or HTTPS URL")
|
|
}
|
|
conf.PrintInfo(Spec.Addr)
|
|
}
|