Skip to content

Commit 03998e5

Browse files
committed
Lint corrections.
1 parent 61273c7 commit 03998e5

File tree

9 files changed

+33
-33
lines changed

9 files changed

+33
-33
lines changed

lib/ipify/ipify.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
var (
2323
ErrNoIP = errors.New("ip address is empty")
2424
ErrInvalid = errors.New("ip address is invalid")
25+
ErrRequest = errors.New("ipify.org error")
2526
ErrStatus = errors.New("unusual ipify.org server response")
2627
)
2728

@@ -45,7 +46,7 @@ func IPv6(ctx context.Context, cancel context.CancelFunc) (string, error) {
4546
// Request the seeip API URL and return a valid IPv4 or IPv6 address.
4647
func Request(ctx context.Context, cancel context.CancelFunc, url string) (string, error) {
4748
b, err := request(ctx, cancel, url)
48-
if b == nil && err == nil && ctx.Err() == context.Canceled {
49+
if b == nil && err == nil && errors.Is(ctx.Err(), context.Canceled) {
4950
return "", nil
5051
}
5152
if err != nil {
@@ -54,13 +55,14 @@ func Request(ctx context.Context, cancel context.CancelFunc, url string) (string
5455
fmt.Printf("\n%s: timeout", domain)
5556
return "", nil
5657
default:
57-
if err == nil && ctx.Err() == context.Canceled {
58+
if err == nil && errors.Is(ctx.Err(), context.Canceled) {
5859
return "", nil
5960
}
60-
if errors.Unwrap(err) == context.Canceled {
61+
if errors.Is(errors.Unwrap(err), context.Canceled) {
6162
return "", nil
6263
}
63-
return "", fmt.Errorf("%s error: %s", domain, err)
64+
e := fmt.Errorf("%w: %s", ErrRequest, err)
65+
return "", e
6466
}
6567
}
6668

@@ -86,8 +88,6 @@ func request(ctx context.Context, cancel context.CancelFunc, url string) ([]byte
8688
}
8789
defer resp.Body.Close()
8890

89-
//log.Printf("\nReceived %d from %s\n", resp.StatusCode, url)
90-
9191
if resp.StatusCode != http.StatusOK {
9292
return nil, fmt.Errorf("%s, %w", strings.ToLower(resp.Status), ErrStatus)
9393
}

lib/ipify/ipify_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func ExampleIPv4() {
2929

3030
s, err := IPv4(ctx, cancel)
3131
if err != nil {
32-
log.Fatalf("\n%s\n", err)
32+
log.Printf("\n%s\n", err)
3333
}
3434
fmt.Println(s)
3535
}

lib/myipcom/myipcom.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
ErrNoIPv4 = errors.New("ip address is not v4")
3434
ErrNoIPv6 = errors.New("ip address is not v6")
3535
ErrInvalid = errors.New("ip address is invalid")
36+
ErrRequest = errors.New("myip.com error")
3637
ErrStatus = errors.New("unusual myip.com server response")
3738
)
3839

@@ -81,7 +82,7 @@ func IPv6(ctx context.Context, cancel context.CancelFunc) (string, error) {
8182
// Request the seeip API URL and return a valid IPv4 or IPv6 address.
8283
func Request(ctx context.Context, cancel context.CancelFunc, url string) (string, error) {
8384
s, err := request(ctx, cancel, url)
84-
if s == "" && err == nil && ctx.Err() == context.Canceled {
85+
if s == "" && err == nil && errors.Is(ctx.Err(), context.Canceled) {
8586
return "", nil
8687
}
8788
if err != nil {
@@ -90,13 +91,14 @@ func Request(ctx context.Context, cancel context.CancelFunc, url string) (string
9091
fmt.Printf("\n%s: timeout", domain)
9192
return "", nil
9293
default:
93-
if err == nil && ctx.Err() == context.Canceled {
94+
if err == nil && errors.Is(ctx.Err(), context.Canceled) {
9495
return "", nil
9596
}
96-
if errors.Unwrap(err) == context.Canceled {
97+
if errors.Is(errors.Unwrap(err), context.Canceled) {
9798
return "", nil
9899
}
99-
return "", fmt.Errorf("%s error: %s", domain, err)
100+
e := fmt.Errorf("%w: %s", ErrRequest, err)
101+
return "", e
100102
}
101103
}
102104

@@ -117,8 +119,6 @@ func request(ctx context.Context, cancel context.CancelFunc, url string) (string
117119
}
118120
defer resp.Body.Close()
119121

120-
//log.Printf("\nReceived %d from %s\n", resp.StatusCode, url)
121-
122122
if resp.StatusCode != http.StatusOK {
123123
return "", fmt.Errorf("%s, %w", strings.ToLower(resp.Status), ErrStatus)
124124
}

lib/myipcom/myipcom_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func ExampleIPv4() {
2929

3030
s, err := IPv4(ctx, cancel)
3131
if err != nil {
32-
log.Fatalf("\n%s\n", err)
32+
log.Printf("\n%s\n", err)
3333
}
3434
fmt.Println(s)
3535
}

lib/myipio/myipio.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
ErrNoIPv4 = errors.New("ip address is not ipv4")
3838
ErrNoIPv6 = errors.New("ip address is not ipv6")
3939
ErrInvalid = errors.New("ip address is invalid")
40+
ErrRequest = errors.New("myip.com error")
4041
ErrStatus = errors.New("unusual my-ip.io server response")
4142
)
4243

@@ -60,7 +61,7 @@ func IPv6(ctx context.Context, cancel context.CancelFunc) (string, error) {
6061
// Request the seeip API URL and return a valid IPv4 or IPv6 address.
6162
func Request(ctx context.Context, cancel context.CancelFunc, url string) (string, error) {
6263
r, err := request(ctx, cancel, url)
63-
if r.IP == "" && err == nil && ctx.Err() == context.Canceled {
64+
if r.IP == "" && err == nil && errors.Is(ctx.Err(), context.Canceled) {
6465
return "", nil
6566
}
6667
if err != nil {
@@ -69,13 +70,14 @@ func Request(ctx context.Context, cancel context.CancelFunc, url string) (string
6970
fmt.Printf("\n%s: timeout", domain)
7071
return "", nil
7172
default:
72-
if err == nil && ctx.Err() == context.Canceled {
73+
if err == nil && errors.Is(ctx.Err(), context.Canceled) {
7374
return "", nil
7475
}
75-
if errors.Unwrap(err) == context.Canceled {
76+
if errors.Is(errors.Unwrap(err), context.Canceled) {
7677
return "", nil
7778
}
78-
return "", fmt.Errorf("%s error: %s", domain, err)
79+
e := fmt.Errorf("%w: %s", ErrRequest, err)
80+
return "", e
7981
}
8082
}
8183

@@ -100,8 +102,6 @@ func request(ctx context.Context, cancel context.CancelFunc, url string) (Result
100102
}
101103
defer resp.Body.Close()
102104

103-
//log.Printf("\nReceived %d from %s\n", resp.StatusCode, url)
104-
105105
if resp.StatusCode != http.StatusOK {
106106
return Result{}, fmt.Errorf("%s, %w", strings.ToLower(resp.Status), ErrStatus)
107107
}

lib/myipio/myipio_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func ExampleIPv4() {
2929

3030
s, err := IPv4(ctx, cancel)
3131
if err != nil {
32-
log.Fatalf("\n%s\n", err)
32+
log.Printf("\n%s\n", err)
3333
}
3434
fmt.Println(s)
3535
}

lib/seeip/seeip.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
var (
2323
ErrNoIP = errors.New("ip address is empty")
2424
ErrInvalid = errors.New("ip address is invalid")
25+
ErrRequest = errors.New("myip.com error")
2526
ErrStatus = errors.New("unusual seeip.org server response")
2627
)
2728

@@ -45,7 +46,7 @@ func IPv6(ctx context.Context, cancel context.CancelFunc) (string, error) {
4546
// Request the seeip API URL and return a valid IPv4 or IPv6 address.
4647
func Request(ctx context.Context, cancel context.CancelFunc, url string) (string, error) {
4748
b, err := request(ctx, cancel, url)
48-
if b == nil && err == nil && ctx.Err() == context.Canceled {
49+
if b == nil && err == nil && errors.Is(ctx.Err(), context.Canceled) {
4950
return "", nil
5051
}
5152
if err != nil {
@@ -54,13 +55,14 @@ func Request(ctx context.Context, cancel context.CancelFunc, url string) (string
5455
fmt.Printf("\n%s: timeout", domain)
5556
return "", nil
5657
default:
57-
if err == nil && ctx.Err() == context.Canceled {
58+
if err == nil && errors.Is(ctx.Err(), context.Canceled) {
5859
return "", nil
5960
}
60-
if errors.Unwrap(err) == context.Canceled {
61+
if errors.Is(errors.Unwrap(err), context.Canceled) {
6162
return "", nil
6263
}
63-
return "", fmt.Errorf("%s error: %s", domain, err)
64+
e := fmt.Errorf("%w: %s", ErrRequest, err)
65+
return "", e
6466
}
6567
}
6668

@@ -86,8 +88,6 @@ func request(ctx context.Context, cancel context.CancelFunc, url string) ([]byte
8688
}
8789
defer resp.Body.Close()
8890

89-
//log.Printf("\nReceived %d from %s\n", resp.StatusCode, url)
90-
9191
if resp.StatusCode != http.StatusOK {
9292
return nil, fmt.Errorf("%s, %w", strings.ToLower(resp.Status), ErrStatus)
9393
}

lib/seeip/seeip_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func BenchmarkRequest(b *testing.B) {
1414
ctx, timeout := context.WithTimeout(context.Background(), 5*time.Second)
1515
r, err := request(ctx, timeout, linkv4)
1616
if err != nil {
17-
fmt.Println(err)
17+
log.Println(err)
1818
return
1919
}
2020
fmt.Println(string(r))
@@ -28,7 +28,7 @@ func ExampleIPv4() {
2828

2929
s, err := IPv4(ctx, cancel)
3030
if err != nil {
31-
log.Fatalf("\n%s\n", err)
31+
log.Printf("\n%s\n", err)
3232
}
3333
fmt.Println(s)
3434
}

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ const (
4343
)
4444

4545
var (
46-
version = "0.0.0" // nolint:gochecknoglobals
47-
commit = "unset" // nolint:gochecknoglobals
48-
date = "unset" // nolint:gochecknoglobals
46+
version = "0.0.0"
47+
commit = "unset" // nolint: gochecknoglobals
48+
date = "unset" // nolint: gochecknoglobals
4949
)
5050

5151
func main() {
@@ -126,7 +126,7 @@ func info() {
126126
}
127127

128128
// Fast waits for the fastest concurrent request to complete
129-
// before aborting and cancelling the others.
129+
// before aborting and canceling the others.
130130
func (p ping) first() {
131131
fmt.Print(p.count())
132132
c := make(chan string)

0 commit comments

Comments
 (0)