mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
add custom endpoints configuration for package grpcx (#2625)
This commit is contained in:
@ -262,10 +262,14 @@ func (s *GrpcServer) GetListenedPort() int {
|
||||
|
||||
func (s *GrpcServer) calculateListenedEndpoints(ctx context.Context) gsvc.Endpoints {
|
||||
var (
|
||||
configAddr = s.config.Address
|
||||
endpoints = make(gsvc.Endpoints, 0)
|
||||
configAddr = s.config.Address
|
||||
endpoints = make(gsvc.Endpoints, 0)
|
||||
configAddrs = s.config.Endpoints
|
||||
)
|
||||
for _, address := range gstr.SplitAndTrim(configAddr, ",") {
|
||||
if len(configAddrs) == 0 {
|
||||
configAddrs = gstr.SplitAndTrim(configAddr, ",")
|
||||
}
|
||||
for _, address := range configAddrs {
|
||||
var (
|
||||
addrArray = gstr.Split(address, ":")
|
||||
listenedIps []string
|
||||
|
||||
@ -28,6 +28,7 @@ type GrpcServerConfig struct {
|
||||
ErrorLogPattern string // (optional) ErrorLogPattern specifies the error log file pattern like: error-{Ymd}.log
|
||||
AccessLogEnabled bool // (optional) AccessLogEnabled enables access logging content to file.
|
||||
AccessLogPattern string // (optional) AccessLogPattern specifies the error log file pattern like: access-{Ymd}.log
|
||||
Endpoints []string // (optional) Address for server register if null use Address value.
|
||||
Options []grpc.ServerOption // (optional) GRPC Server options.
|
||||
}
|
||||
|
||||
|
||||
36
contrib/rpc/grpcx/grpcx_grpc_server_config_test.go
Normal file
36
contrib/rpc/grpcx/grpcx_grpc_server_config_test.go
Normal file
@ -0,0 +1,36 @@
|
||||
package grpcx
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gogf/gf/v2/test/gtest"
|
||||
)
|
||||
|
||||
func Test_Grpcx_Grpc_Server_Config(t *testing.T) {
|
||||
cfg := Server.NewConfig()
|
||||
addr := "10.0.0.29:80"
|
||||
cfg.Endpoints = []string{
|
||||
addr,
|
||||
}
|
||||
// cfg set one endpoint
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
s := Server.New(cfg)
|
||||
s.doServiceRegister()
|
||||
for _, svc := range s.services {
|
||||
t.Assert(svc.GetEndpoints().String(), addr)
|
||||
}
|
||||
})
|
||||
// cfg set more endpoints
|
||||
addr = "10.0.0.29:80,10.0.0.29:81"
|
||||
cfg.Endpoints = []string{
|
||||
"10.0.0.29:80",
|
||||
"10.0.0.29:81",
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
s := Server.New(cfg)
|
||||
s.doServiceRegister()
|
||||
for _, svc := range s.services {
|
||||
t.Assert(svc.GetEndpoints().String(), addr)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user