-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Add ability to ignore fields that match given regex pattern(s) #199
Conversation
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.
A couple of comments, but I like the idea.
options.go
Outdated
// | ||
// Example: When referencing protoc generated structs, you will likely want to | ||
// ignore/skip XXX_* fields. | ||
func IgnoreFieldsRegex(regexes ...*regexp.Regexp) Option { |
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.
Please change this accept strings, and compile the regexes in the OptionFunc. It would be tedious to require users to compile their patterns.
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.
Sure thing!
build.go
Outdated
for _, field := range fields { | ||
for _, r := range k.ignoreFieldsRegex { | ||
if r.Match([]byte(field.field.Name)) { |
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.
Use MatchString()
instead of casting.
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.
Please match against v.Type().Name + "." + field.field.Name
so that it can match against the containing struct as well. It's fairly common in deeply nested CLI structures to repeat fields and being able to discriminate by the containing "command" will future proof this.
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.
Gotcha. Will do.
build.go
Outdated
for _, field := range fields { | ||
for _, r := range k.ignoreFieldsRegex { | ||
if r.Match([]byte(field.field.Name)) { | ||
fmt.Println("skipping field: ", field.field.Name) |
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.
Remove.
Thanks for this, I love getting contributions! :) |
Thank YOU - you did all the hard work! I added an extra test for options - noticed something was untested when running a coverage report for my own stuff. All feedback should be addressed. |
@alecthomas this adds functionality to allow kong to ignore fields that match a certain pattern.
I needed this in order to be able to ensure that kong does not parse fields like
XXX_
that are automatically generated via protoc.The regexp is kind of a big hammer but since this is for CLI generation, I figure the perf hit is OK. LMK.