Go proposal: Compare IP subnets
18 points by cgrinds
18 points by cgrinds
You can also write the sort as slices.SortFunc(prefixes, netip.Prefix.Compare) because methods are equivalent to functions with the receiver as the first argument.
Then by masked IP address (network IP).
10.0.0.0/8 < 10.0.1.0/8
Should this be /24 instead?
This is actually really great. There are a lot of edge-cases here.
I don't say this often about Python, but my favorite API for analyzing IP networks and subnets is Python 3's ipaddress module
https://docs.python.org/3/library/ipaddress.html
Any time I need to analyze subnets in Go I always end up using Python 3 to check my work :)