41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Package config 使用仓库统一的 BSM 运行配置与地址校验。
|
|
package config
|
|
|
|
import (
|
|
"net"
|
|
|
|
"git.apinb.com/bsm-sdk/core/conf"
|
|
)
|
|
|
|
// Spec 是 Worker 运行配置。
|
|
var Spec SrvConfig
|
|
|
|
// SrvConfig 保持与 API 进程相同的 BSM 配置结构。
|
|
type SrvConfig struct {
|
|
conf.Base `yaml:",inline"`
|
|
Databases *conf.DBConf `yaml:"Databases"`
|
|
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
|
|
Apm *conf.ApmConf `yaml:"APM"`
|
|
PaymentAPI PaymentAPIConfig `yaml:"PaymentAPI"`
|
|
}
|
|
|
|
// PaymentAPIConfig 保存 Worker 调用支付内部动作所需的最小配置。
|
|
type PaymentAPIConfig struct {
|
|
BaseURL string `yaml:"BaseURL"`
|
|
Token string `yaml:"Token"`
|
|
IntervalSeconds int `yaml:"IntervalSeconds"`
|
|
}
|
|
|
|
// New 初始化 Worker 配置。
|
|
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.PaymentAPI.BaseURL == "" || Spec.PaymentAPI.Token == "" || Spec.PaymentAPI.IntervalSeconds <= 0 {
|
|
panic("PaymentAPI configuration is required")
|
|
}
|
|
conf.PrintInfo(Spec.Addr)
|
|
}
|