chore(all): replace net.IP with netip.Addr
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
@@ -28,13 +28,13 @@ var (
|
||||
)
|
||||
|
||||
// FetchInfo obtains information on the ip address provided
|
||||
// using the ipinfo.io API. If the ip is nil, the public IP address
|
||||
// using the ipinfo.io API. If the ip is the zero value, the public IP address
|
||||
// of the machine is used as the IP.
|
||||
func (f *Fetch) FetchInfo(ctx context.Context, ip net.IP) (
|
||||
func (f *Fetch) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||
result Response, err error) {
|
||||
const baseURL = "https://ipinfo.io/"
|
||||
url := baseURL
|
||||
if ip != nil {
|
||||
if ip.IsValid() {
|
||||
url += ip.String()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package ipinfo
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/netip"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
IP net.IP `json:"ip,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
City string `json:"city,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Loc string `json:"loc,omitempty"`
|
||||
Org string `json:"org,omitempty"`
|
||||
Postal string `json:"postal,omitempty"`
|
||||
Timezone string `json:"timezone,omitempty"`
|
||||
IP netip.Addr `json:"ip,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
City string `json:"city,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Loc string `json:"loc,omitempty"`
|
||||
Org string `json:"org,omitempty"`
|
||||
Postal string `json:"postal,omitempty"`
|
||||
Timezone string `json:"timezone,omitempty"`
|
||||
}
|
||||
|
||||
func (r *Response) ToPublicIPModel() (model models.PublicIP) {
|
||||
model = models.PublicIP{
|
||||
IP: make(net.IP, len(r.IP)),
|
||||
return models.PublicIP{
|
||||
IP: r.IP,
|
||||
Region: r.Region,
|
||||
Country: r.Country,
|
||||
City: r.City,
|
||||
@@ -30,6 +30,4 @@ func (r *Response) ToPublicIPModel() (model models.PublicIP) {
|
||||
PostalCode: r.Postal,
|
||||
Timezone: r.Timezone,
|
||||
}
|
||||
copy(model.IP, r.IP)
|
||||
return model
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package ipinfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
// FetchMultiInfo obtains the public IP address information for every IP
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// If an error is encountered, all the operations are canceled and
|
||||
// an error is returned, so the results returned should be considered
|
||||
// incomplete in this case.
|
||||
func (f *Fetch) FetchMultiInfo(ctx context.Context, ips []net.IP) (
|
||||
func (f *Fetch) FetchMultiInfo(ctx context.Context, ips []netip.Addr) (
|
||||
results []Response, err error) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
|
||||
@@ -23,7 +23,7 @@ func (f *Fetch) FetchMultiInfo(ctx context.Context, ips []net.IP) (
|
||||
resultsCh := make(chan asyncResult)
|
||||
|
||||
for i, ip := range ips {
|
||||
go func(index int, ip net.IP) {
|
||||
go func(index int, ip netip.Addr) {
|
||||
aResult := asyncResult{
|
||||
index: index,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user