AlexStocks commented on code in PR #3186:
URL: https://github.com/apache/dubbo-go/pull/3186#discussion_r2772002544
##########
global/router_config.go:
##########
@@ -53,6 +57,23 @@ type ConditionRule struct {
To []ConditionRuleTo `yaml:"to" json:"to,omitempty" property:"to"`
}
+// Equal checks if two ConditionRule instances are equal.
+// It treats nil and empty To slices as equal by comparing their lengths.
+func (x *ConditionRule) Equal(t *ConditionRule) bool {
Review Comment:
// Equal checks if two ConditionRule instances are equal.
func (x *ConditionRule) Equal(t *ConditionRule) bool {
// 1. 指针地址相同或者是双 nil,直接返回真
if x == t {
return true
}
// 2. 其中一个是 nil,另一个不是,直接返回假
if x == nil || t == nil {
return false
}
// 3. 比较 From 部分
// 如果 ConditionRuleFrom 支持 == 比较,请直接使用 x.From == t.From
if !reflect.DeepEqual(x.From, t.From) {
return false
}
// 4. 比较 To 部分 (兼容 nil 与 empty)
if len(x.To) != len(t.To) {
return false
}
// 如果长度都为 0 (可能是 nil 或 []),直接过,避免后续 range
if len(x.To) == 0 {
return true
}
// 5. 循环比较元素
for i := range x.To {
// 同样,如果 ConditionRuleTo 结构简单,建议换掉 reflect.DeepEqual
if !reflect.DeepEqual(x.To[i], t.To[i]) {
return false
}
}
return true
}
--
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]