feat: split all grpc and http endpoints

This commit is contained in:
2026-08-11 18:47:27 +08:00
parent 3ba0bafc37
commit 53e953c3fc
8 changed files with 435 additions and 31 deletions

View File

@@ -11,10 +11,13 @@ import (
senderService "bsm/full/module/base/sender/service"
walletService "bsm/full/module/finance/wallet/service"
"git.apinb.com/bsm-sdk/core/conf"
"git.apinb.com/bsm-sdk/core/printer"
)
type SrvConfig struct {
conf.Base `yaml:",inline"`
Server ServerConfig `yaml:"Server"`
DynamicRPC DynamicRPCConfig `yaml:"DynamicRPC"`
Databases *conf.DBConf `yaml:"Databases"`
MicroService *conf.MicroServiceConf `yaml:"MicroService"`
Rpc map[string]conf.RpcConf `yaml:"Rpc"`
@@ -28,16 +31,44 @@ type SrvConfig struct {
Wallet *walletService.Config `yaml:"Wallet"`
}
type ListenerConfig struct {
BindIP string `yaml:"BindIP"`
Port string `yaml:"Port"`
Addr string `yaml:"-"`
}
type ServerConfig struct {
GRPC ListenerConfig `yaml:"GRPC"`
HTTP ListenerConfig `yaml:"HTTP"`
}
type DynamicRPCConfig struct {
Allow []string `yaml:"Allow"`
}
var Spec SrvConfig
func New(serviceKey string) {
conf.New(serviceKey, &Spec)
Spec.Port = conf.CheckPort(Spec.Port)
Spec.BindIP = conf.CheckIP(Spec.BindIP)
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
normalizeListener(&Spec.Server.GRPC)
normalizeListener(&Spec.Server.HTTP)
if Spec.Server.GRPC.Addr == Spec.Server.HTTP.Addr {
panic("gRPC and HTTP listeners must use different addresses")
}
// Keep the embedded base address meaningful for module configurations that
// still consume it, while all itself uses the two explicit listeners.
Spec.BindIP, Spec.Port, Spec.Addr = Spec.Server.HTTP.BindIP, Spec.Server.HTTP.Port, Spec.Server.HTTP.Addr
conf.NotNil(Spec.Service, Spec.Cache)
assignSharedConfig()
conf.PrintInfo(Spec.Addr)
conf.PrintInfo(Spec.Server.GRPC.Addr)
printer.Info("gRPC Address: %s", Spec.Server.GRPC.Addr)
printer.Info("HTTP Address: %s", Spec.Server.HTTP.Addr)
}
func normalizeListener(listener *ListenerConfig) {
listener.Port = conf.CheckPort(listener.Port)
listener.BindIP = conf.CheckIP(listener.BindIP)
listener.Addr = net.JoinHostPort(listener.BindIP, listener.Port)
}
func assignSharedConfig() {