Mulavar commented on a change in pull request #1260:
URL: https://github.com/apache/dubbo-go/pull/1260#discussion_r657048754



##########
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:
       strJudger.Judge(str) 为 true 的时候需要遍历下一个条件继续做judge,不能直接返回




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

Reply via email to