chore(all): replace net.IP with netip.Addr
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
@@ -81,25 +79,6 @@ func CopyLogLevelPtr(original *log.Level) (copied *log.Level) {
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyIP(original net.IP) (copied net.IP) {
|
||||
if original == nil {
|
||||
return nil
|
||||
}
|
||||
copied = make(net.IP, len(original))
|
||||
copy(copied, original)
|
||||
return copied
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
return copied
|
||||
}
|
||||
|
||||
func CopyStringSlice(original []string) (copied []string) {
|
||||
if original == nil {
|
||||
return nil
|
||||
@@ -136,9 +115,6 @@ func CopyNetipAddressesSlice(original []netip.Addr) (copied []netip.Addr) {
|
||||
}
|
||||
|
||||
copied = make([]netip.Addr, len(original))
|
||||
for i := range original {
|
||||
copied[i] = CopyNetipAddress(original[i])
|
||||
}
|
||||
|
||||
copy(copied, original)
|
||||
return copied
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/log"
|
||||
@@ -101,9 +101,9 @@ func DefaultLogLevel(existing *log.Level,
|
||||
return result
|
||||
}
|
||||
|
||||
func DefaultIP(existing net.IP, defaultValue net.IP) (
|
||||
result net.IP) {
|
||||
if existing != nil {
|
||||
func DefaultIP(existing netip.Addr, defaultValue netip.Addr) (
|
||||
result netip.Addr) {
|
||||
if existing.IsValid() {
|
||||
return existing
|
||||
}
|
||||
return defaultValue
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"net"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"time"
|
||||
@@ -96,14 +96,17 @@ func MergeWithUint32(existing, other *uint32) (result *uint32) {
|
||||
return result
|
||||
}
|
||||
|
||||
func MergeWithIP(existing, other net.IP) (result net.IP) {
|
||||
if existing != nil {
|
||||
func MergeWithIP(existing, other netip.Addr) (result netip.Addr) {
|
||||
if existing.IsValid() {
|
||||
return existing
|
||||
} else if !other.IsValid() {
|
||||
return existing
|
||||
} else if other == nil {
|
||||
return nil
|
||||
}
|
||||
result = make(net.IP, len(other))
|
||||
copy(result, other)
|
||||
|
||||
result, ok := netip.AddrFromSlice(other.AsSlice())
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("failed copying other address: %s", other))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"net"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"time"
|
||||
@@ -84,12 +84,14 @@ func OverrideWithUint32(existing, other *uint32) (result *uint32) {
|
||||
return result
|
||||
}
|
||||
|
||||
func OverrideWithIP(existing, other net.IP) (result net.IP) {
|
||||
if other == nil {
|
||||
func OverrideWithIP(existing, other netip.Addr) (result netip.Addr) {
|
||||
if !other.IsValid() {
|
||||
return existing
|
||||
}
|
||||
result = make(net.IP, len(other))
|
||||
copy(result, other)
|
||||
result, ok := netip.AddrFromSlice(other.AsSlice())
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("failed copying other address: %s", other))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user