-
Notifications
You must be signed in to change notification settings - Fork 6
fix merge struct issues #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* prefer `figtree:"name=value"` tag for field names. * prevent duplicate conflicts between yaml names and struct field names.
figtree.go
Outdated
| case aOk && bOk: | ||
| // if both defined, pick the first one | ||
| resultTag = append(resultTag, fmt.Sprintf("%s:%q", tag, aTag)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems redundant with case aOk below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged the cases
figtree.go
Outdated
| if prev, ok := seen[value.Name]; ok { | ||
| // we have a duplicate field name, this should not happen | ||
| // but if it does, we will just skip it | ||
| fmt.Fprintf(os.Stderr, "Duplicate field name %q in merge struct.\n\tOld: %s %s `%s`\n\tNew: %s %s `%s`\n", value.Name, prev.Name, prev.Type.String(), prev.Tag, value.Name, value.Type.String(), value.Tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this debugging code? Not sure we want figtree to print to os.Stderr on its own accord. I'd suggest either:
- A panic if this shouldn't be possible to trigger
- Silently ignored if it can happen but isn't actionable
- Pass in a logger if it's something we want to bubble up non-fatally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up converting these to panics. The reflect.MakeStruct call will panic below if we have duplicate fields, so better to panic here with slightly friendlier output.
figtree.go
Outdated
| if prev, ok := yamlSeen[yamlName]; yamlName != "" && ok { | ||
| // we have a duplicate field name, this should not happen | ||
| // but if it does, we will just skip it | ||
| fmt.Fprintf(os.Stderr, "Duplicate YAML tag %q in merge struct.\n\tOld: %s %s `%s`\n\tNew: %s %s `%s`\n", yamlName, prev.Name, prev.Type.String(), prev.Tag, value.Name, value.Type.String(), value.Tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern about printing to stderr
Optiontypes, select the type that both merge types are assignable to (ieOption[string]vsOption[any],Option[any]will be chosen).figtree:"name=value"tag for field names.