refactor: reorganize modules and add Linux build tooling
This commit is contained in:
45
module/ec/mall/internal/config/config.go
Normal file
45
module/ec/mall/internal/config/config.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"git.apinb.com/bsm-sdk/core/crypto/encipher"
|
||||
"git.apinb.com/bsm-sdk/core/env"
|
||||
)
|
||||
|
||||
var (
|
||||
Spec SrvConfig // 全局服务配置实例
|
||||
)
|
||||
|
||||
// SrvConfig 服务配置结构体
|
||||
type SrvConfig struct {
|
||||
conf.Base `yaml:",inline"` // 基础配置(服务名、端口、缓存等)
|
||||
Databases *conf.DBConf `yaml:"Databases"` // 数据库配置
|
||||
MicroService *conf.MicroServiceConf `yaml:"MicroService"` // 微服务配置
|
||||
Rpc map[string]conf.RpcConf `yaml:"Rpc"` // RPC服务配置
|
||||
Gateway *conf.GatewayConf `yaml:"Gateway"` // 网关配置
|
||||
Apm *conf.ApmConf `yaml:"APM"` // APM监控配置
|
||||
Etcd *conf.EtcdConf `yaml:"Etcd"` // Etcd配置
|
||||
}
|
||||
|
||||
// New 初始化服务配置
|
||||
func New(srvKey string) {
|
||||
// 初始化配置 - 创建一个新的配置实例,用于服务配置
|
||||
conf.New(srvKey, &Spec)
|
||||
|
||||
// 配置校验 - 服务IP和端口校验,端口如果不合规则随机分配端口
|
||||
Spec.Port = conf.CheckPort(Spec.Port)
|
||||
Spec.BindIP = conf.CheckIP(Spec.BindIP)
|
||||
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
|
||||
Spec.Log = conf.InitLoggerConf(Spec.Log)
|
||||
|
||||
// 配置校验 - 服务名称、地址及监听地址不能为空
|
||||
conf.NotNil(Spec.Service, Spec.Cache)
|
||||
|
||||
// 初始化加密SecretKey
|
||||
encipher.New(env.Runtime.JwtSecretKey)
|
||||
|
||||
// 打印服务启动信息
|
||||
conf.PrintInfo(Spec.Addr)
|
||||
}
|
||||
Reference in New Issue
Block a user