KamToHung commented on code in PR #3034:
URL: https://github.com/apache/dubbo-go/pull/3034#discussion_r2443329620
##########
protocol/grpc/server.go:
##########
@@ -150,22 +151,35 @@ func (s *Server) Start(url *common.URL) {
s.grpcServer = server
go func() {
- providerServices := config.GetProviderConfig().Services
-
- if len(providerServices) == 0 {
- panic("provider service map is null")
- }
- // wait all exporter ready , then set proxy impl and grpc
registerService
+ providerServices := s.getProviderServices(url)
+ // wait all exporter ready, then set proxy impl and grpc
registerService
waitGrpcExporter(providerServices)
registerService(providerServices, server)
reflection.Register(server)
-
- if err = server.Serve(lis); err != nil {
+ if err := server.Serve(lis); err != nil {
logger.Errorf("server serve failed with err: %v", err)
}
}()
}
+// getProviderServices retrieves provider services from config or URL
attributes
+func (s *Server) getProviderServices(url *common.URL)
map[string]*global.ServiceConfig {
+ providerServices := config.GetProviderConfig().Services
+ if len(providerServices) > 0 {
+ return convertServiceMap(providerServices)
+ }
+ // TODO #2741 old config compatibility
+ providerConfRaw, ok := url.GetAttribute(constant.ProviderConfigKey)
+ if !ok {
+ panic("no provider service found")
+ }
+ providerConf, ok := providerConfRaw.(*global.ProviderConfig)
+ if !ok || providerConf == nil {
+ panic("illegal provider config")
+ }
+ return providerConf.Services
Review Comment:
Thanks,I fix it
##########
protocol/grpc/server.go:
##########
@@ -150,22 +151,35 @@ func (s *Server) Start(url *common.URL) {
s.grpcServer = server
go func() {
- providerServices := config.GetProviderConfig().Services
-
- if len(providerServices) == 0 {
- panic("provider service map is null")
- }
- // wait all exporter ready , then set proxy impl and grpc
registerService
+ providerServices := s.getProviderServices(url)
+ // wait all exporter ready, then set proxy impl and grpc
registerService
waitGrpcExporter(providerServices)
registerService(providerServices, server)
reflection.Register(server)
-
- if err = server.Serve(lis); err != nil {
+ if err := server.Serve(lis); err != nil {
logger.Errorf("server serve failed with err: %v", err)
}
}()
}
+// getProviderServices retrieves provider services from config or URL
attributes
+func (s *Server) getProviderServices(url *common.URL)
map[string]*global.ServiceConfig {
+ providerServices := config.GetProviderConfig().Services
+ if len(providerServices) > 0 {
+ return convertServiceMap(providerServices)
+ }
+ // TODO #2741 old config compatibility
+ providerConfRaw, ok := url.GetAttribute(constant.ProviderConfigKey)
+ if !ok {
+ panic("no provider service found")
+ }
+ providerConf, ok := providerConfRaw.(*global.ProviderConfig)
+ if !ok || providerConf == nil {
+ panic("illegal provider config")
+ }
+ return providerConf.Services
Review Comment:
Thanks, I fix it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]