chore(all): replace net.IP with netip.Addr
This commit is contained in:
@@ -2,15 +2,16 @@ package updater
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
func parseIPv4(s string) (ipv4 net.IP, err error) {
|
||||
ip := net.ParseIP(s)
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("%w: %q", ErrParseIP, s)
|
||||
} else if ip.To4() == nil {
|
||||
return nil, fmt.Errorf("%w: %s", ErrNotIPv4, ip)
|
||||
func parseIPv4(s string) (ipv4 netip.Addr, err error) {
|
||||
ipv4, err = netip.ParseAddr(s)
|
||||
if err != nil {
|
||||
return ipv4, err
|
||||
}
|
||||
return ip, nil
|
||||
if !ipv4.Is4() {
|
||||
return ipv4, fmt.Errorf("%w: %s", ErrNotIPv4, ipv4)
|
||||
}
|
||||
return ipv4, nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/netip"
|
||||
"sort"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrParseIP = errors.New("cannot parse IP address")
|
||||
ErrNotIPv4 = errors.New("IP address is not IPv4")
|
||||
)
|
||||
|
||||
@@ -47,7 +46,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) (
|
||||
Region: jsonServer.Country,
|
||||
Hostname: jsonServer.Domain,
|
||||
Number: number,
|
||||
IPs: []net.IP{ip},
|
||||
IPs: []netip.Addr{ip},
|
||||
TCP: jsonServer.Features.TCP,
|
||||
UDP: jsonServer.Features.UDP,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user