Move from net to netip#46
Open
monoidic wants to merge 3 commits intoyl2chen:masterfrom
Open
Conversation
Author
|
This would be a breaking change, and thus would require a 2.x release. If we're going to break compatibility, we might as well include other valuable changes, such as a switch from use of exposed interfaces (Ranger, RangerEntry) to using concrete types with generics. I believe the Ranger interface itself is just an anti-pattern, while RangerEntry is perhaps intended to allow associating data with a key, which generics would do in a cleaner and cheaper way since Go 1.18. |
|
For example, this PR is an incomplete/WIP adjustment of the API for generics building upon this PR. |
|
FYI to those looking for this, I’m going to try out https://github.com/gaissmai/bart as a replacement, might be useful to others |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR moves cidranger from using the IP address/prefix values from the
"net"module in the Go standard libary to using the equivalents from the newer"net/netip"in the standard library. This allows for some code simplification:[]bytelengths or nil pointersnetip.Prefixcan be used directly as a map key in bruteranger as opposed to anet.IPNet's.String()value==/!=as opposed to viabytes.Equal()The tests were updated to use
net/netip, and run successfully.TestInsertErrorandTestRemoveErrorwere removed, as the error they are testing for is impossible to induce withnet/netipThis is a fairly big update, and since it changes a good chunk of the API, likely warrants a version bump, though I am opening this PR to at least see if this is a change that you are interested in and if you have any changes in mind.
net/netipwas introduced in 1.18, and, as 1.19 is out now, all officially supported versions of Go (the last two releases) support this, though applications and libraries making use of cidranger would need to be rewritten or at least add wrapper code to handle this, if this version is used.