Copilot commented on code in PR #2868:
URL: https://github.com/apache/dubbo-go/pull/2868#discussion_r2094553461


##########
server/options.go:
##########
@@ -80,6 +80,11 @@ func (srvOpts *ServerOptions) init(opts ...ServerOption) 
error {
 
        prov := srvOpts.Provider
 
+       if srvOpts.Provider.Weight <= 0 {
+               logger.Debugf("weight should be greater than 0, set to default 
value %d", constant.DefaultWeight)
+               prov.Weight = constant.DefaultWeight

Review Comment:
   Modifying `prov.Weight` only affects the local copy; assign directly to 
`srvOpts.Provider.Weight` to update the actual server options.
   ```suggestion
                srvOpts.Provider.Weight = constant.DefaultWeight
   ```



##########
registry/nacos/service_discovery.go:
##########
@@ -315,13 +312,12 @@ func (n *nacosServiceDiscovery) 
toRegisterInstance(instance registry.ServiceInst
                metadata = make(map[string]string, 1)
        }
 
-       weightStr := 
n.registryURL.GetParam(constant.RegistryKey+"."+constant.WeightKey, "1.0")
-       weight, err := strconv.ParseFloat(weightStr, 64)
-       if err != nil || weight <= constant.MinNacosWeight {
-               logger.Warnf("Invalid weight value %q, using default 1.0. err: 
%v", weightStr, err)
+       weight := instance.GetWeight()
+       if weight <= constant.MinNacosWeight {
+               logger.Warnf("Invalid weight value %d, using default weight 
%d.", weight, constant.DefaultWeight)
                weight = constant.DefaultNacosWeight
        } else if weight > constant.MaxNacosWeight {
-               logger.Warnf("Weight %f exceeds Nacos maximum 10000, setting to 
10000", weight)
+               logger.Warnf("Weight %d exceeds Nacos maximum 10000, setting to 
10000", weight)

Review Comment:
   [nitpick] Avoid hardcoding `10000` in log messages; use 
`constant.MaxNacosWeight` to keep the message consistent with the configured 
limit.
   ```suggestion
                logger.Warnf("Weight %d exceeds Nacos maximum %d, setting to 
%d", weight, constant.MaxNacosWeight, constant.MaxNacosWeight)
   ```



##########
registry/nacos/service_discovery.go:
##########
@@ -315,13 +312,12 @@ func (n *nacosServiceDiscovery) 
toRegisterInstance(instance registry.ServiceInst
                metadata = make(map[string]string, 1)
        }
 
-       weightStr := 
n.registryURL.GetParam(constant.RegistryKey+"."+constant.WeightKey, "1.0")
-       weight, err := strconv.ParseFloat(weightStr, 64)
-       if err != nil || weight <= constant.MinNacosWeight {
-               logger.Warnf("Invalid weight value %q, using default 1.0. err: 
%v", weightStr, err)
+       weight := instance.GetWeight()
+       if weight <= constant.MinNacosWeight {
+               logger.Warnf("Invalid weight value %d, using default weight 
%d.", weight, constant.DefaultWeight)

Review Comment:
   The log references `constant.DefaultWeight` but the code falls back to 
`constant.DefaultNacosWeight`. Update the message to use the correct constant 
for clarity.
   ```suggestion
                logger.Warnf("Invalid weight value %d, using default weight 
%d.", weight, constant.DefaultNacosWeight)
   ```



##########
registry/service_instance.go:
##########
@@ -175,7 +188,9 @@ func (d *DefaultServiceInstance) ToURLs(service 
*info.ServiceInfo) []*common.URL
                                        common.WithIp(d.Host), 
common.WithPort(strconv.Itoa(endpoint.Port)),
                                        common.WithPath(service.Name), 
common.WithInterface(service.Name),
                                        
common.WithMethods(service.GetMethods()), 
common.WithParams(service.GetParams()),
-                                       
common.WithParams(url2.Values{constant.Tagkey: {d.Tag}}))
+                                       
common.WithParams(url2.Values{constant.Tagkey: {d.Tag}}),
+                                       
common.WithParamsValue(constant.WeightKey, d.GetMetadata()[constant.WeightKey]),

Review Comment:
   This uses the raw metadata string and may be empty; use `d.GetWeight()` and 
format with `strconv.FormatInt` to ensure a valid weight parameter in the URL.
   ```suggestion
                                        
common.WithParamsValue(constant.WeightKey, strconv.FormatInt(d.GetWeight(), 
10)),
   ```



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