chore(all): format code using gofumpt

This commit is contained in:
Quentin McGaw
2024-10-20 13:12:33 +00:00
parent 4c7c794494
commit 05d566c807
104 changed files with 308 additions and 178 deletions

View File

@@ -79,7 +79,8 @@ func Test_IPv6(t *testing.T) {
func Fuzz_IPv6(f *testing.F) {
f.Fuzz(func(_ *testing.T, ipv6A, ipv6B, ipv6C []byte,
garbageA, garbageB, garbageC string) {
garbageA, garbageB, garbageC string,
) {
var arrayA [16]byte
if len(ipv6A) > 0 {
copy(arrayA[:], ipv6A)

View File

@@ -20,7 +20,8 @@ var (
)
func fetch(ctx context.Context, client Client, network string,
providerData providerData) (publicIPs []netip.Addr, err error) {
providerData providerData,
) (publicIPs []netip.Addr, err error) {
var serverHost string
switch network {
case "tcp":
@@ -80,9 +81,7 @@ func fetch(ctx context.Context, client Client, network string,
return publicIPs, nil
}
var (
ErrTooManyTXTRecords = errors.New("too many TXT records")
)
var ErrTooManyTXTRecords = errors.New("too many TXT records")
func handleAnswerTXT(answer dns.RR) (publicIP netip.Addr, err error) {
answerTXT, ok := answer.(*dns.TXT)

View File

@@ -11,9 +11,7 @@ import (
"github.com/miekg/dns"
)
var (
ErrIPNotFoundForVersion = errors.New("IP addresses found but not for IP version")
)
var ErrIPNotFoundForVersion = errors.New("IP addresses found but not for IP version")
func (f *Fetcher) IP(ctx context.Context) (publicIP netip.Addr, err error) {
publicIPs, err := f.ip(ctx, "tcp")
@@ -52,7 +50,8 @@ func (f *Fetcher) IP6(ctx context.Context) (publicIP netip.Addr, err error) {
}
func (f *Fetcher) ip(ctx context.Context, network string) (
publicIPs []netip.Addr, err error) {
publicIPs []netip.Addr, err error,
) {
index := int(atomic.AddUint32(f.ring.counter, 1)) % len(f.ring.providers)
providerData := f.ring.providers[index].data()

View File

@@ -20,7 +20,8 @@ var (
)
func fetch(ctx context.Context, client *http.Client, url string,
version ipversion.IPVersion) (publicIP netip.Addr, err error) {
version ipversion.IPVersion,
) (publicIP netip.Addr, err error) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return netip.Addr{}, err

View File

@@ -23,7 +23,8 @@ func (f *Fetcher) IP6(ctx context.Context) (publicIP netip.Addr, err error) {
}
func (f *Fetcher) ip(ctx context.Context, ring *urlsRing, version ipversion.IPVersion) (
publicIP netip.Addr, err error) {
publicIP netip.Addr, err error,
) {
ring.mutex.Lock()
var index int

View File

@@ -109,7 +109,8 @@ func Test_fetcher_IP6(t *testing.T) {
httpBytes := []byte(`::1`)
expectedPublicIP := netip.AddrFrom16([16]byte{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1})
0, 0, 0, 0, 0, 0, 0, 1,
})
client := &http.Client{
Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {

View File

@@ -19,8 +19,10 @@ func Test_ListProvidersForVersion(t *testing.T) {
}{
"ip4or6": {
version: ipversion.IP4or6,
providers: []Provider{Ifconfig, Ipify, Ipinfo, Spdyn, Ipleak,
Icanhazip, Ident, Nnev, Wtfismyip, Seeip, Changeip},
providers: []Provider{
Ifconfig, Ipify, Ipinfo, Spdyn, Ipleak,
Icanhazip, Ident, Nnev, Wtfismyip, Seeip, Changeip,
},
},
"ip4": {
version: ipversion.IP4,

View File

@@ -19,7 +19,8 @@ type ip2Location struct {
}
func (p *ip2Location) get(ctx context.Context, ip netip.Addr) (
result Result, err error) {
result Result, err error,
) {
result.Source = string(Ipinfo)
url := "https://api.ip2location.io/"

View File

@@ -19,7 +19,8 @@ type ipinfo struct {
}
func (p *ipinfo) get(ctx context.Context, ip netip.Addr) (
result Result, err error) {
result Result, err error,
) {
result.Source = string(Ipinfo)
url := "https://ipinfo.io/"