nanjiek commented on code in PR #3309:
URL: https://github.com/apache/dubbo-go/pull/3309#discussion_r3152197572
##########
registry/servicediscovery/service_discovery_registry.go:
##########
@@ -115,6 +115,10 @@ func (s *serviceDiscoveryRegistry) RegisterService() error
{
func createInstance(meta *info.MetadataInfo, url *common.URL)
registry.ServiceInstance {
params := make(map[string]string, 8)
params[constant.MetadataStorageTypePropertyName] =
metadata.GetMetadataType()
+ // Keep routing attributes visible on the registered instance as well
as in service metadata.
+ if environment := url.GetParam(constant.EnvironmentKey, "");
environment != "" {
Review Comment:
用len判断替代!=好一些
```suggestion
// Keep routing attributes visible on the registered instance as well
as in service metadata.
if environment := url.GetParam(constant.EnvironmentKey, "");
len(environment) > 0{
```
##########
registry/servicediscovery/service_instances_changed_listener_impl.go:
##########
@@ -183,6 +178,25 @@ func (lstn *ServiceInstancesChangedListenerImpl) OnEvent(e
observer.Event) error
return nil
}
+func toInstanceServiceURLs(instance registry.ServiceInstance, serviceInfo
*info.ServiceInfo) []*common.URL {
+ urls := instance.ToURLs(serviceInfo)
+ environment := ""
+ if metadata := instance.GetMetadata(); metadata != nil {
+ environment = metadata[constant.EnvironmentKey]
+ }
+ // Environment is instance-level routing metadata and is not part of
the revision hash.
+ // Treat the fresh instance value as authoritative so same-revision
restarts
+ // can update or clear stale metadata cached by revision.
+ for _, url := range urls {
+ if environment != "" {
+ url.SetParam(constant.EnvironmentKey, environment)
+ } else {
+ url.DelParam(constant.EnvironmentKey)
+ }
+ }
+ return urls
Review Comment:
建议使用卫语句,提高可读性
```suggestion
if metadata == nil {
for _, u := range urls {
u.DelParam(constant.EnvironmentKey)
}
return urls
}
env, ok := metadata[constant.EnvironmentKey]
for _, u := range urls {
if ok && len(env) > 0 {
u.SetParam(constant.EnvironmentKey, env)
} else {
u.DelParam(constant.EnvironmentKey)
}
}
return urls
```
--
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]