AsperforMias commented on code in PR #1126:
URL: 
https://github.com/apache/incubator-seata-go/pull/1126#discussion_r3487405840


##########
pkg/discovery/init.go:
##########
@@ -26,40 +26,30 @@ var (
 )
 
 func InitRegistry(serviceConfig *ServiceConfig, registryConfig 
*RegistryConfig) {
-       var registryService RegistryService
-       var err error
-       switch registryConfig.Type {
-       case FILE:
-               //init file registry
-               registryService = newFileRegistryService(serviceConfig)
-       case ETCD:
-               //init etcd registry
-               registryService = newEtcdRegistryService(serviceConfig, 
&registryConfig.Etcd3)
-       case RAFT:
-               registryService = NewRaftRegistryService(serviceConfig, 
registryConfig)
-       case NACOS:
-               //TODO: init nacos registry
-       case EUREKA:
-               //TODO: init eureka registry
-       case REDIS:
-               //TODO: init redis registry
-       case ZK:
-               //TODO: init zk registry
-       case CONSUL:
-               //TODO: init consul registry
-       case SOFA:
-               //TODO: init sofa registry
-       case NAMINGSERVER:
-               // init namingserver registry
-               registryService = newNamingServerRegistryService(serviceConfig, 
&registryConfig.NamingServer)
-       default:
-               err = fmt.Errorf("service registry not support registry 
type:%s", registryConfig.Type)
+       if err := InitRegistryWithError(serviceConfig, registryConfig); err != 
nil {
+               panic(fmt.Errorf("init service registry err:%v", err))
        }
+}
 
+func InitRegistryWithError(serviceConfig *ServiceConfig, registryConfig 
*RegistryConfig) error {
+       if registryConfig == nil {
+               return fmt.Errorf("registry config is nil")
+       }
+
+       provider, ok := registryProviderFor(registryConfig.Type)
+       if !ok {
+               return unsupportedRegistryTypeError(registryConfig.Type)
+       }
+
+       registryService, err := provider(serviceConfig, registryConfig)
        if err != nil {
-               panic(fmt.Errorf("init service registry err:%v", err))
+               return err

Review Comment:
   这里失败时会保留旧的 registryServiceInstance。看上去是为了兼容旧 InitRegistry 的 panic 语义?但 
InitRegistryWithError 作为新 API,最好再补个测试明确一下:已有 registry 后再初始化失败,GetRegistry 
应该继续返回旧实例or变成 nil



-- 
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]

Reply via email to