|
|
@ -38,6 +38,7 @@ import (
|
|
|
|
"github.com/openimsdk/tools/errs"
|
|
|
|
"github.com/openimsdk/tools/errs"
|
|
|
|
"github.com/openimsdk/tools/log"
|
|
|
|
"github.com/openimsdk/tools/log"
|
|
|
|
"github.com/openimsdk/tools/mw"
|
|
|
|
"github.com/openimsdk/tools/mw"
|
|
|
|
|
|
|
|
grpcsrv "github.com/openimsdk/tools/mw/grpc/server"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -76,6 +77,34 @@ func getConfigRpcMaxRequestBody(value reflect.Value) *conf.MaxRequestBody {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func getConfigShare(value reflect.Value) *conf.Share {
|
|
|
|
|
|
|
|
for value.Kind() == reflect.Pointer {
|
|
|
|
|
|
|
|
value = value.Elem()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if value.Kind() == reflect.Struct {
|
|
|
|
|
|
|
|
num := value.NumField()
|
|
|
|
|
|
|
|
for i := 0; i < num; i++ {
|
|
|
|
|
|
|
|
field := value.Field(i)
|
|
|
|
|
|
|
|
if !field.CanInterface() {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for field.Kind() == reflect.Pointer {
|
|
|
|
|
|
|
|
field = field.Elem()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch elem := field.Interface().(type) {
|
|
|
|
|
|
|
|
case conf.Share:
|
|
|
|
|
|
|
|
return &elem
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if field.Kind() == reflect.Struct {
|
|
|
|
|
|
|
|
if elem := getConfigShare(field); elem != nil {
|
|
|
|
|
|
|
|
return elem
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *conf.Prometheus, listenIP,
|
|
|
|
func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *conf.Prometheus, listenIP,
|
|
|
|
registerIP string, autoSetPorts bool, rpcPorts []int, index int, rpcRegisterName string, notification *conf.Notification, config T,
|
|
|
|
registerIP string, autoSetPorts bool, rpcPorts []int, index int, rpcRegisterName string, notification *conf.Notification, config T,
|
|
|
|
watchConfigNames []string, watchServiceNames []string,
|
|
|
|
watchConfigNames []string, watchServiceNames []string,
|
|
|
@ -87,12 +116,20 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
maxRequestBody := getConfigRpcMaxRequestBody(reflect.ValueOf(config))
|
|
|
|
maxRequestBody := getConfigRpcMaxRequestBody(reflect.ValueOf(config))
|
|
|
|
|
|
|
|
shareConfig := getConfigShare(reflect.ValueOf(config))
|
|
|
|
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "rpc start", "rpcMaxRequestBody", maxRequestBody, "rpcRegisterName", rpcRegisterName, "registerIP", registerIP, "listenIP", listenIP)
|
|
|
|
log.ZDebug(ctx, "rpc start", "rpcMaxRequestBody", maxRequestBody, "rpcRegisterName", rpcRegisterName, "registerIP", registerIP, "listenIP", listenIP)
|
|
|
|
|
|
|
|
|
|
|
|
options = append(options,
|
|
|
|
options = append(options,
|
|
|
|
mw.GrpcServer(),
|
|
|
|
grpcsrv.GrpcServerMetadataContext(),
|
|
|
|
|
|
|
|
grpcsrv.GrpcServerLogger(),
|
|
|
|
|
|
|
|
grpcsrv.GrpcServerErrorConvert(),
|
|
|
|
|
|
|
|
grpcsrv.GrpcServerRequestValidate(),
|
|
|
|
|
|
|
|
grpcsrv.GrpcServerPanicCapture(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if shareConfig != nil && len(shareConfig.IMAdminUserID) > 0 {
|
|
|
|
|
|
|
|
options = append(options, grpcServerIMAdminUserID(shareConfig.IMAdminUserID))
|
|
|
|
|
|
|
|
}
|
|
|
|
var clientOptions []grpc.DialOption
|
|
|
|
var clientOptions []grpc.DialOption
|
|
|
|
if maxRequestBody != nil {
|
|
|
|
if maxRequestBody != nil {
|
|
|
|
if maxRequestBody.RequestMaxBodySize > 0 {
|
|
|
|
if maxRequestBody.RequestMaxBodySize > 0 {
|
|
|
|