Copilot commented on code in PR #982:
URL: https://github.com/apache/dubbo-go-pixiu/pull/982#discussion_r3420454733
##########
pkg/adapter/springcloud/servicediscovery/nacos/nacos.go:
##########
@@ -118,7 +118,14 @@ func (n *nacosServiceDiscovery) Callback(services
[]xdsmodel.SubscribeService, e
continue
}
- instance := fromSubscribeServiceToServiceInstance(service)
+ // v2 subscribe callback receives Instance directly (was
SubscribeService in v1)
+ // ServiceName may contain group prefix like
"DEFAULT_GROUP@@service-name", strip it
+ serviceName := service.ServiceName
+ if tmp := strings.Split(serviceName, "@@"); len(tmp) == 2 {
+ serviceName = tmp[1]
+ }
+
+ instance := fromInstanceToServiceInstance(serviceName, service)
Review Comment:
Using `strings.Split` here allocates a slice and only handles exactly 2
parts; if the string contains more than one `"@@"`, the prefix won’t be
stripped. Prefer `strings.Cut(serviceName, "@@")` (or
`strings.SplitN(serviceName, "@@", 2)`) to express “split once” clearly and
avoid unnecessary allocations.
##########
pkg/adapter/springcloud/servicediscovery/nacos/nacos.go:
##########
@@ -118,7 +118,14 @@ func (n *nacosServiceDiscovery) Callback(services
[]xdsmodel.SubscribeService, e
continue
}
- instance := fromSubscribeServiceToServiceInstance(service)
+ // v2 subscribe callback receives Instance directly (was
SubscribeService in v1)
+ // ServiceName may contain group prefix like
"DEFAULT_GROUP@@service-name", strip it
+ serviceName := service.ServiceName
+ if tmp := strings.Split(serviceName, "@@"); len(tmp) == 2 {
+ serviceName = tmp[1]
+ }
+
+ instance := fromInstanceToServiceInstance(serviceName, service)
key := instance.GetUniqKey()
newInstanceMap[instance.GetUniqKey()] = instance
Review Comment:
`GetUniqKey()` is computed twice back-to-back. Reuse `key` for the map write
(`newInstanceMap[key] = instance`) to avoid duplicate work and keep the intent
clearer.
--
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]