-
-
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
feat: added mapper for regex #427
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.
Love it, awesome idea.
For those linter failures, just add |
Ok i will do it |
mapper.go
Outdated
RegisterType(reflect.TypeOf(netip.Addr{}), netipAddrMapper()). | ||
RegisterType(reflect.TypeOf(netip.Prefix{}), netipPrefixMapper()). |
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.
sorry for the drive-by review, but are these two actually necessary? 🤔
they implement enconding.TextUnmarshaller
and should work out of the box?
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.
you are right, they work out of the box
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 removed the netip mappers from the pr, and cleanup my tests.
I thought about also removing the net mappers, and only add the regex mapper:
- this would guide users to use new new netip package instead of the net package
What do you think about that?
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.
Good question. Maybe both? I don't think there's any harm there.
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 like the idea of leading people to netip. Especially since the package already has convenience code for converting back and forth to net.IP and friends.
But that's just my 2¢
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.
As mentioned in the comment, I'd personally leave the "legacy" net.IP stuff out to nudge people toward netip
but the PR looks great as is! 👍
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.
🚀
mapper.go
Outdated
@@ -733,6 +735,30 @@ func fileContentMapper(r *Registry) MapperFunc { | |||
} | |||
} | |||
|
|||
func regexMapper() MapperFunc { |
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.
regexp.Regexp
actually implements encoding.Text(Un)marshaler
, so I don't think this is necessary either after all...
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.
oh boy, you're right! 🤦
totally overlooked that too 🙈
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.
sorry for consuming you time 🤦
i removed all mappers. we can close those this pr.
I added some regex tests in the last commit, if you have some time, maybe you can explain to me why the TestRegex,TestRegexSlice,TestRegexPointer are working but the TestRegexPointerSlice is not?
- somehow i used to always use
*regex.Regexp
instead ofregex.Regexp
but the pointer version does not with the slice
added mappers for:
netip.Prefixnet.IPnet.IPNetregexp.Regexp