AlexStocks commented on code in PR #3160:
URL: https://github.com/apache/dubbo-go/pull/3160#discussion_r2689672985


##########
common/url.go:
##########
@@ -869,20 +875,38 @@ func (c *URL) MergeURL(anotherUrl *URL) *URL {
 
 // Clone will copy the URL
 func (c *URL) Clone() *URL {

Review Comment:
   ```go
   // CloneWithFilter - Clone the URL with parameter filtering
   // excludeParams: the set of parameters to exclude from the cloned URL
   // reserveParams: the set of parameters to retain in the cloned URL
   func (c *URL) CloneWithFilter(excludeParams *gxset.HashSet, reserveParams 
[]string) *URL {
       newURL := &URL{
           Protocol:     c.Protocol,
           Location:     c.Location,
           Ip:           c.Ip,
           Port:         c.Port,
           PrimitiveURL: c.PrimitiveURL,
           Path:         c.Path,
           Username:     c.Username,
           Password:     c.Password,
           Methods:      append(make([]string, 0), c.Methods...),
           attributes:   make(map[string]any),
           params:       url.Values{},
       }
   
       // Copy and filter params based on excludeParams or reserveParams
       c.RangeParams(func(key, value string) bool {
           // If the param is in excludeParams or not in reserveParams, skip it
           if (excludeParams != nil && excludeParams.Contains(key)) || 
              (len(reserveParams) > 0 && !contains(reserveParams, key)) {
               return true
           }
           // Set the param if it passes the filter
           newURL.SetParam(key, value)
           return true
       })
   
       // Copy attributes
       c.RangeAttributes(func(key string, value any) bool {
           newURL.SetAttribute(key, value)
           return true
       })
   
       // Copy SubURL if it exists
       if c.SubURL != nil {
           newURL.SubURL = c.SubURL.Clone()
       }
   
       return newURL
   }
   
   // Clone - Clone all contents including params and attributes
   func (c *URL) Clone() *URL {
       return c.CloneWithFilter(nil, nil) // No exclusion or reservation, clone 
everything
   }
   
   // CloneExceptParams - Clone all contents, but exclude params in 
excludeParams
   func (c *URL) CloneExceptParams(excludeParams *gxset.HashSet) *URL {
       return c.CloneWithFilter(excludeParams, nil) // Only exclude specified 
params
   }
   
   // CloneWithParams - Clone and keep only the specified params
   func (c *URL) CloneWithParams(reserveParams []string) *URL {
       return c.CloneWithFilter(nil, reserveParams) // Only keep specified 
params
   }
   
   // Helper function: Check if a slice contains a specific element
   func contains(slice []string, item string) bool {
       for _, v := range slice {
           if v == item {
               return true
           }
       }
       return false
   }
   ```
   
   原代码重复部分太多,请使用新代码



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