Snow-kal commented on code in PR #3171:
URL: https://github.com/apache/dubbo-go/pull/3171#discussion_r2719823187


##########
filter/generic/generalizer/map.go:
##########
@@ -84,6 +81,41 @@ func (g *MapGeneralizer) GetType(obj any) (typ string, err 
error) {
        return
 }
 
+func getGenericIncludeClass() bool {
+       return true
+}
+
+func removeClass(obj any) any {
+       switch v := obj.(type) {
+       case map[string]any:
+               m := make(map[string]any, len(v))
+               for k, val := range v {
+                       if k == "class" {
+                               continue
+                       }
+                       m[k] = removeClass(val)
+               }
+               return m
+       case map[any]any:
+               m := make(map[any]any, len(v))
+               for k, val := range v {
+                       if k == "class" {
+                               continue
+                       }
+                       m[k] = removeClass(val)
+               }
+               return m
+       case []any:
+               s := make([]any, 0, len(v))
+               for _, val := range v {
+                       s = append(s, removeClass(val))
+               }
+               return s
+       default:
+               return obj
+       }
+}

Review Comment:
   已添加注释说明,简要概述其用途
   ```
   // getGenericIncludeClass retrieves "generic.include.class" config value 
(fallback to true)
   func getGenericIncludeClass() bool {
        cfgList := config.GetEnvInstance().Configuration()
        for e := cfgList.Front(); e != nil; e = e.Next() {
                conf, ok := e.Value.(*config.InmemoryConfiguration)
                if !ok {
                        continue
                }
   
                if exist, val := 
conf.GetProperty(constant.GenericIncludeClassKey); exist {
                        parsed, err := strconv.ParseBool(val)
                        if err != nil {
                                logger.Warnf("generic.include.class value %q is 
invalid, fallback to true", val)
                                return true
                        }
                        return parsed
                }
        }
   
        return true
   }
   
   // removeClass recursively removes "class" key from data (returns new copy, 
no original modify)
   // obj: any data (map[string]any/map[any]any/[]any/basic type)
   func removeClass(obj any) any {
        switch v := obj.(type) {
        case map[string]any:
                m := make(map[string]any, len(v))
                for k, val := range v {
                        if k == "class" {
                                continue
                        }
                        m[k] = removeClass(val)
                }
                return m
        case map[any]any:
                m := make(map[any]any, len(v))
                for k, val := range v {
                        if k == "class" {
                                continue
                        }
                        m[k] = removeClass(val)
                }
                return m
        case []any:
                s := make([]any, 0, len(v))
                for _, val := range v {
                        s = append(s, removeClass(val))
                }
                return s
        default:
                return obj
        }
   }
   ```



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

Reply via email to