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 returns if "class" field should be retained
(always true)
func getGenericIncludeClass() bool {
return true
}
// removeClass recursively removes "class" key from data (returns new copy)
// obj: any data (map/slice/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]