gaoxinge commented on a change in pull request #1260: URL: https://github.com/apache/dubbo-go/pull/1260#discussion_r652326144
########## File path: cluster/router/v3router/judger/list_string_match_judger_test.go ########## @@ -0,0 +1,34 @@ +/* + * 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 judger + +import ( + "dubbo.apache.org/dubbo-go/v3/config" Review comment: move to a new import block, like https://github.com/apache/dubbo-go/blob/master/contributing.md#34-import ########## File path: cluster/router/v3router/judger/attachment_match_judger.go ########## @@ -29,45 +29,34 @@ type AttachmentMatchJudger struct { // nolint func (amj *AttachmentMatchJudger) Judge(invocation protocol.Invocation) bool { invAttaMap := invocation.Attachments() - if amj.EagleeyeContext != nil { - for k, v := range amj.EagleeyeContext { - invAttaValue, ok := invAttaMap[k] - if !ok { - if v.Empty == "" { - return false - } - continue - } - // exist this key - str, ok := invAttaValue.(string) - if !ok { - return false - } - strJudger := NewStringMatchJudger(v) - if !strJudger.Judge(str) { - return false - } - } + if amj.EagleeyeContext != nil && !judge(amj.EagleeyeContext, invAttaMap) { + return false } - if amj.DubboContext != nil { - for k, v := range amj.DubboContext { - invAttaValue, ok := invAttaMap[k] - if !ok { - if v.Empty == "" { - return false - } - continue - } - // exist this key - str, ok := invAttaValue.(string) - if !ok { - return false - } - strJudger := NewStringMatchJudger(v) - if !strJudger.Judge(str) { + if amj.DubboContext != nil && !judge(amj.DubboContext, invAttaMap) { + return false + } + + return true +} + +func judge(condition map[string]*config.StringMatch, invAttaMap map[string]interface{}) bool { + for k, v := range condition { + invAttaValue, ok := invAttaMap[k] + if !ok { + if v.Empty == "" { return false } + continue + } + // exist this key + str, ok := invAttaValue.(string) + if !ok { + return false + } + strJudger := NewStringMatchJudger(v) + if !strJudger.Judge(str) { Review comment: directly use `return strJudger.Judge(str)` ########## File path: cluster/router/v3router/judger/attachment_match_judger.go ########## @@ -29,45 +29,34 @@ type AttachmentMatchJudger struct { // nolint func (amj *AttachmentMatchJudger) Judge(invocation protocol.Invocation) bool { invAttaMap := invocation.Attachments() - if amj.EagleeyeContext != nil { - for k, v := range amj.EagleeyeContext { - invAttaValue, ok := invAttaMap[k] - if !ok { - if v.Empty == "" { - return false - } - continue - } - // exist this key - str, ok := invAttaValue.(string) - if !ok { - return false - } - strJudger := NewStringMatchJudger(v) - if !strJudger.Judge(str) { - return false - } - } + if amj.EagleeyeContext != nil && !judge(amj.EagleeyeContext, invAttaMap) { + return false } - if amj.DubboContext != nil { - for k, v := range amj.DubboContext { - invAttaValue, ok := invAttaMap[k] - if !ok { - if v.Empty == "" { - return false - } - continue - } - // exist this key - str, ok := invAttaValue.(string) - if !ok { - return false - } - strJudger := NewStringMatchJudger(v) - if !strJudger.Judge(str) { + if amj.DubboContext != nil && !judge(amj.DubboContext, invAttaMap) { Review comment: directly use `return amj.DubboContext == nil || judge(amj.DubboContext, invAttaMap)` ########## File path: cluster/router/v3router/judger/attachment_match_judger.go ########## @@ -29,45 +29,34 @@ type AttachmentMatchJudger struct { // nolint func (amj *AttachmentMatchJudger) Judge(invocation protocol.Invocation) bool { invAttaMap := invocation.Attachments() - if amj.EagleeyeContext != nil { - for k, v := range amj.EagleeyeContext { - invAttaValue, ok := invAttaMap[k] - if !ok { - if v.Empty == "" { - return false - } - continue - } - // exist this key - str, ok := invAttaValue.(string) - if !ok { - return false - } - strJudger := NewStringMatchJudger(v) - if !strJudger.Judge(str) { - return false - } - } + if amj.EagleeyeContext != nil && !judge(amj.EagleeyeContext, invAttaMap) { + return false } - if amj.DubboContext != nil { - for k, v := range amj.DubboContext { - invAttaValue, ok := invAttaMap[k] - if !ok { - if v.Empty == "" { - return false - } - continue - } - // exist this key - str, ok := invAttaValue.(string) - if !ok { - return false - } - strJudger := NewStringMatchJudger(v) - if !strJudger.Judge(str) { + if amj.DubboContext != nil && !judge(amj.DubboContext, invAttaMap) { + return false + } + + return true +} + +func judge(condition map[string]*config.StringMatch, invAttaMap map[string]interface{}) bool { + for k, v := range condition { + invAttaValue, ok := invAttaMap[k] + if !ok { + if v.Empty == "" { return false } + continue + } + // exist this key + str, ok := invAttaValue.(string) + if !ok { + return false + } + strJudger := NewStringMatchJudger(v) + if !strJudger.Judge(str) { Review comment: directly use `return strJudger.Judge(str)` ########## File path: cluster/router/v3router/judger/url_label_match_judge_test.go ########## @@ -0,0 +1,35 @@ +/* + * 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 judger + +import ( + "dubbo.apache.org/dubbo-go/v3/common" Review comment: move to a new import block, like https://github.com/apache/dubbo-go/blob/master/contributing.md#34-import ########## File path: cluster/router/v3router/judger/method_match_judger_test.go ########## @@ -0,0 +1,72 @@ +/* + * 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 judger + +import ( + "dubbo.apache.org/dubbo-go/v3/config" + "dubbo.apache.org/dubbo-go/v3/protocol/invocation" Review comment: move to a new import block, like https://github.com/apache/dubbo-go/blob/master/contributing.md#34-import -- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
