chore(settings): inet.af/netaddr -> net/netip
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
func CopyStringPtr(original *string) (copied *string) {
|
||||
@@ -113,21 +114,17 @@ func CopyIPNetPtr(original *net.IPNet) (copied *net.IPNet) {
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyNetaddrIP(original netaddr.IP) (copied netaddr.IP) {
|
||||
b, err := original.MarshalBinary()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
func CopyNetipAddress(original netip.Addr) (copied netip.Addr) {
|
||||
// AsSlice creates a new byte slice so no need to copy the bytes.
|
||||
bytes := original.AsSlice()
|
||||
copied, ok := netip.AddrFromSlice(bytes)
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("cannot deep copy address with bytes %#v", bytes))
|
||||
}
|
||||
|
||||
err = copied.UnmarshalBinary(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyIPPrefix(original netaddr.IPPrefix) (copied netaddr.IPPrefix) {
|
||||
func CopyNetipPrefix(original netip.Prefix) (copied netip.Prefix) {
|
||||
b, err := original.MarshalText()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -173,26 +170,26 @@ func CopyIPNetSlice(original []net.IPNet) (copied []net.IPNet) {
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyIPPrefixSlice(original []netaddr.IPPrefix) (copied []netaddr.IPPrefix) {
|
||||
func CopyNetipPrefixesSlice(original []netip.Prefix) (copied []netip.Prefix) {
|
||||
if original == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
copied = make([]netaddr.IPPrefix, len(original))
|
||||
copied = make([]netip.Prefix, len(original))
|
||||
for i := range original {
|
||||
copied[i] = CopyIPPrefix(original[i])
|
||||
copied[i] = CopyNetipPrefix(original[i])
|
||||
}
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyNetaddrIPsSlice(original []netaddr.IP) (copied []netaddr.IP) {
|
||||
func CopyNetipAddressesSlice(original []netip.Addr) (copied []netip.Addr) {
|
||||
if original == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
copied = make([]netaddr.IP, len(original))
|
||||
copied = make([]netip.Addr, len(original))
|
||||
for i := range original {
|
||||
copied[i] = CopyNetaddrIP(original[i])
|
||||
copied[i] = CopyNetipAddress(original[i])
|
||||
}
|
||||
|
||||
return copied
|
||||
|
||||
@@ -3,10 +3,10 @@ package helpers
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
func MergeWithBool(existing, other *bool) (result *bool) {
|
||||
@@ -213,13 +213,13 @@ func MergeIPNetsSlices(a, b []net.IPNet) (result []net.IPNet) {
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeNetaddrIPsSlices(a, b []netaddr.IP) (result []netaddr.IP) {
|
||||
func MergeNetipAddressesSlices(a, b []netip.Addr) (result []netip.Addr) {
|
||||
if a == nil && b == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
seen := make(map[string]struct{}, len(a)+len(b))
|
||||
result = make([]netaddr.IP, 0, len(a)+len(b))
|
||||
result = make([]netip.Addr, 0, len(a)+len(b))
|
||||
for _, ip := range a {
|
||||
key := ip.String()
|
||||
if _, ok := seen[key]; ok {
|
||||
@@ -239,13 +239,13 @@ func MergeNetaddrIPsSlices(a, b []netaddr.IP) (result []netaddr.IP) {
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeIPPrefixesSlices(a, b []netaddr.IPPrefix) (result []netaddr.IPPrefix) {
|
||||
func MergeNetipPrefixesSlices(a, b []netip.Prefix) (result []netip.Prefix) {
|
||||
if a == nil && b == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
seen := make(map[string]struct{}, len(a)+len(b))
|
||||
result = make([]netaddr.IPPrefix, 0, len(a)+len(b))
|
||||
result = make([]netip.Prefix, 0, len(a)+len(b))
|
||||
for _, ipPrefix := range a {
|
||||
key := ipPrefix.String()
|
||||
if _, ok := seen[key]; ok {
|
||||
|
||||
@@ -3,10 +3,10 @@ package helpers
|
||||
import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
"inet.af/netaddr"
|
||||
)
|
||||
|
||||
func OverrideWithBool(existing, other *bool) (result *bool) {
|
||||
@@ -154,20 +154,20 @@ func OverrideWithIPNetsSlice(existing, other []net.IPNet) (result []net.IPNet) {
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithNetaddrIPsSlice(existing, other []netaddr.IP) (result []netaddr.IP) {
|
||||
func OverrideWithNetipAddressesSlice(existing, other []netip.Addr) (result []netip.Addr) {
|
||||
if other == nil {
|
||||
return existing
|
||||
}
|
||||
result = make([]netaddr.IP, len(other))
|
||||
result = make([]netip.Addr, len(other))
|
||||
copy(result, other)
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithIPPrefixesSlice(existing, other []netaddr.IPPrefix) (result []netaddr.IPPrefix) {
|
||||
func OverrideWithNetipPrefixesSlice(existing, other []netip.Prefix) (result []netip.Prefix) {
|
||||
if other == nil {
|
||||
return existing
|
||||
}
|
||||
result = make([]netaddr.IPPrefix, len(other))
|
||||
result = make([]netip.Prefix, len(other))
|
||||
copy(result, other)
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user