Copilot commented on code in PR #3065: URL: https://github.com/apache/dubbo-go/pull/3065#discussion_r2471588787
########## global/router_config.go: ########## @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package global + +import ( + "dubbo.apache.org/dubbo-go/v3/common" +) + +type RouterConfig struct { + Scope string `validate:"required" yaml:"scope" json:"scope,omitempty" property:"scope"` + Key string `validate:"required" yaml:"key" json:"key,omitempty" property:"key"` + Force *bool `default:"false" yaml:"force" json:"force,omitempty" property:"force"` + Runtime *bool `default:"false" yaml:"runtime" json:"runtime,omitempty" property:"runtime"` + Enabled *bool `default:"true" yaml:"enabled" json:"enabled,omitempty" property:"enabled"` + Valid *bool `default:"true" yaml:"valid" json:"valid,omitempty" property:"valid"` + Priority int `default:"0" yaml:"priority" json:"priority,omitempty" property:"priority"` + Conditions []string `yaml:"conditions" json:"conditions,omitempty" property:"conditions"` + Tags []Tag `yaml:"tags" json:"tags,omitempty" property:"tags"` + ScriptType string `yaml:"type" json:"type,omitempty" property:"type"` + Script string `yaml:"script" json:"script,omitempty" property:"script"` +} + +type Tag struct { + Name string `yaml:"name" json:"name,omitempty" property:"name"` + Match []*common.ParamMatch `yaml:"match" json:"match,omitempty" property:"match"` + Addresses []string `yaml:"addresses" json:"addresses,omitempty" property:"addresses"` +} + +func DefaultRouterConfig() *RouterConfig { + return &RouterConfig{ + Conditions: make([]string, 0), + Tags: make([]Tag, 0), + } +} + +func (c *RouterConfig) Clone() *RouterConfig { + if c == nil { + return nil + } + + var newForce *bool + if c.Force != nil { + newForce = new(bool) + *newForce = *c.Force + } + + var newRuntime *bool + if c.Runtime != nil { + newRuntime = new(bool) + *newRuntime = *c.Runtime + } + + var newEnabled *bool + if c.Enabled != nil { + newEnabled = new(bool) + *newEnabled = *c.Enabled + } + + var newValid *bool + if c.Valid != nil { + newValid = new(bool) + *newValid = *c.Valid + } + + newConditions := make([]string, len(c.Conditions)) + copy(newConditions, c.Conditions) + + newTags := make([]Tag, len(c.Tags)) + copy(newTags, c.Tags) Review Comment: Shallow copy of Tags slice creates shared references to ParamMatch pointers. The Tag struct contains a `Match` field of type `[]*common.ParamMatch`, which means the pointers will be shared between the original and cloned objects. This should perform a deep copy by iterating through each Tag and cloning its Match slice. Example fix: ```go newTags := make([]Tag, len(c.Tags)) for i, tag := range c.Tags { newMatch := make([]*common.ParamMatch, len(tag.Match)) for j, match := range tag.Match { if match != nil { matchCopy := *match newMatch[j] = &matchCopy } } newAddresses := make([]string, len(tag.Addresses)) copy(newAddresses, tag.Addresses) newTags[i] = Tag{ Name: tag.Name, Match: newMatch, Addresses: newAddresses, } } ``` ```suggestion for i, tag := range c.Tags { // Deep copy Match slice newMatch := make([]*common.ParamMatch, len(tag.Match)) for j, match := range tag.Match { if match != nil { matchCopy := *match newMatch[j] = &matchCopy } } // Deep copy Addresses slice newAddresses := make([]string, len(tag.Addresses)) copy(newAddresses, tag.Addresses) newTags[i] = Tag{ Name: tag.Name, Match: newMatch, Addresses: newAddresses, } } ``` ########## compat.go: ########## @@ -437,6 +443,41 @@ func compatShutdownConfig(c *global.ShutdownConfig) *config.ShutdownConfig { return cfg } +func compatRouterConfig(c *global.RouterConfig) *config.RouterConfig { + if c == nil { + return nil + } + return &config.RouterConfig{ + Scope: c.Scope, + Key: c.Key, + Force: c.Force, + Runtime: c.Runtime, + Enabled: c.Enabled, + Valid: c.Valid, + Priority: c.Priority, + Conditions: c.Conditions, + Tags: compatTags(c.Tags), + ScriptType: c.ScriptType, + Script: c.Script, + } + Review Comment: Extra blank line before closing brace. Remove the blank line at line 463 to maintain consistency with the codebase style (see compatShutdownConfig at line 443 and other similar functions). ```suggestion ``` -- 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]
