Hello guys, I submitted a <question> on Github and...
# fluent-operator
x
Hello guys, I submitted a question on Github and found suspicious code.
Copy code
for 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
Copy code
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 it
e
Exceeded the expected number of times means?
x
The name of the custom Parser under the namespace does not match, resulting in a not found error message during startup
Can you give me a correct example? I want to use JSON's Parser in the namespace