Alanxtl commented on code in PR #3066: URL: https://github.com/apache/dubbo-go/pull/3066#discussion_r2501624043
########## 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: here ########## compat.go: ########## @@ -953,6 +999,40 @@ func compatGlobalShutdownConfig(c *config.ShutdownConfig) *global.ShutdownConfig return cfg } +func compatGlobalRouterConfig(c *config.RouterConfig) *global.RouterConfig { + if c == nil { + return nil + } + return &global.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: compatGlobalTag(c.Tags), + ScriptType: c.ScriptType, + Script: c.Script, + } +} + +func compatGlobalTag(c []config.Tag) []global.Tag { + if c == nil { + return nil + } + tags := make([]global.Tag, len(c)) + for i, tag := range c { + tags[i] = global.Tag{ + Name: tag.Name, + Match: tag.Match, + Addresses: tag.Addresses, + } + } Review Comment: 这几个地方clone tag的方法统一一下,统一成深拷贝吧 ########## compat.go: ########## @@ -437,6 +442,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, + } + +} + +func compatTags(c []global.Tag) []config.Tag { + if c == nil { + return nil + } + tags := make([]config.Tag, len(c)) + for i, tag := range c { + tags[i] = config.Tag{ + Name: tag.Name, + Match: tag.Match, + Addresses: tag.Addresses, + } + } + return tags Review Comment: here -- 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]
