45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
// Package config 使用仓库统一的 BSM 运行配置与地址校验。
|
|
package config
|
|
|
|
import (
|
|
"git.apinb.com/bsm-sdk/core/conf"
|
|
"net"
|
|
)
|
|
|
|
var Spec SrvConfig
|
|
|
|
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"`
|
|
IoTAPI IoTAPIConfig `yaml:"IoTAPI"`
|
|
}
|
|
type PaymentAPIConfig struct {
|
|
BaseURL string `yaml:"BaseURL"`
|
|
Token string `yaml:"Token"`
|
|
IntervalSeconds int `yaml:"IntervalSeconds"`
|
|
}
|
|
type IoTAPIConfig struct {
|
|
PlatformBaseURL string `yaml:"PlatformBaseURL"`
|
|
GatewayBaseURL string `yaml:"GatewayBaseURL"`
|
|
Token string `yaml:"Token"`
|
|
IntervalMilliseconds int `yaml:"IntervalMilliseconds"`
|
|
}
|
|
|
|
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")
|
|
}
|
|
if Spec.IoTAPI.PlatformBaseURL == "" || Spec.IoTAPI.GatewayBaseURL == "" || Spec.IoTAPI.Token == "" || Spec.IoTAPI.IntervalMilliseconds <= 0 {
|
|
panic("IoTAPI configuration is required")
|
|
}
|
|
conf.PrintInfo(Spec.Addr)
|
|
}
|