xiangbei
11/13/2023, 6:53 AMfor i := 0; i < reflect.ValueOf(elem).NumField(); i++ {
p, _ := reflect.ValueOf(elem).Field(i).Interface().(plugins.Plugin)
if err := merge(p); err != nil {
return "", err
}
}
The purpose of this code is to traverse every field in the elem and execute the merge function on each field. The merge function contains processing code for the Parser field. If there is a problem with this loop structure, such as exceeding the expected number of loops, it may cause the hash value of the namespace to be added multiple times.I have attempted to modify it
for i := 0; i < reflect.ValueOf(elem).NumField(); i++ {
p, _ := reflect.ValueOf(elem).Field(i).Interface().(plugins.Plugin)
if p != nil {
if parser, ok := p.(*Parser); ok {
namespaceHash := fmt.Sprintf("%x", md5.Sum([]byte(item.Namespace)))
if strings.Contains(parser.Parser, namespaceHash) {
continue
}
}
}
if err := merge(p); err != nil {
return "", err
}
}
I am not sure if my judgment is correct, and I would like your help. If you have any suggestions or opinions, I would greatly appreciate itelon cheng
11/23/2023, 7:58 AMxiangbei
11/27/2023, 2:41 AMxiangbei
11/27/2023, 3:06 AM