Skip to content

Commit 091d6e0

Browse files
committed
更新依赖
1 parent f82cc55 commit 091d6e0

File tree

15 files changed

+92
-358
lines changed

15 files changed

+92
-358
lines changed

.goreleaser.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
dir: cmd/pping
8+
goos:
9+
- linux
10+
- darwin
11+
- windows
12+
goarch:
13+
- "386"
14+
- amd64
15+
ignore:
16+
- goos: darwin
17+
goarch: "386"
18+
archives:
19+
- name_template: >-
20+
{{ .ProjectName }}_
21+
{{- .Version }}_
22+
{{- title .Os }}_
23+
{{- if eq .Arch "amd64" }}x86_64
24+
{{- else if eq .Arch "386" }}i386
25+
{{- else }}{{ .Arch }}{{ end }}
26+
{{- if .Arm }}v{{ .Arm }}{{ end }}
27+
format_overrides:
28+
- goos: windows
29+
format: zip
30+
checksum:
31+
name_template: "checksums.txt"
32+
changelog:
33+
sort: asc
34+
filters:
35+
exclude:
36+
- "^docs:"
37+
- "^test:"
38+
- Merge pull request
39+
- Merge branch

.goreleaser.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

cmd/pping/cmd/root.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import (
1717
var rootCmd *cobra.Command
1818

1919
var Version string
20-
var PingError error = errors.New("ping error")
20+
var ErrPing error = errors.New("ping error")
2121

2222
type globalFlags struct {
23-
v bool
2423
t bool
2524
n int
2625
i time.Duration
@@ -62,7 +61,7 @@ func init() {
6261
func Execute() error {
6362
rootCmd.Version = Version
6463
err := rootCmd.Execute()
65-
if err != nil && err != PingError {
64+
if err != nil && err != ErrPing {
6665
rootCmd.PrintErrf("Error: %v\n", err)
6766
}
6867
return err
@@ -121,7 +120,7 @@ end:
121120
s.print()
122121
}
123122
if s.sent == 0 || s.failed != 0 {
124-
return PingError
123+
return ErrPing
125124
}
126125
return nil
127126
}

cmd/pping/cmd/tcp.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
)
1212

1313
type tcpFlags struct {
14-
port uint16
1514
timeout time.Duration
1615
}
1716

cmd/pping/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func main() {
1313
log.SetFlags(log.Ltime)
1414
cmd.Version = version
1515
err := cmd.Execute()
16-
if err == cmd.PingError {
16+
if err == cmd.ErrPing {
1717
os.Exit(1)
1818
} else if err != nil {
1919
os.Exit(2)

go.mod

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
module github.com/wzv5/pping
22

3-
go 1.14
3+
go 1.19
44

55
require (
6-
github.com/miekg/dns v1.1.38
7-
github.com/spf13/cobra v1.1.3
8-
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
6+
github.com/miekg/dns v1.1.53
7+
github.com/spf13/cobra v1.7.0
8+
golang.org/x/net v0.9.0
9+
)
10+
11+
require (
12+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
13+
github.com/spf13/pflag v1.0.5 // indirect
14+
golang.org/x/mod v0.10.0 // indirect
15+
golang.org/x/sys v0.7.0 // indirect
16+
golang.org/x/tools v0.8.0 // indirect
917
)

go.sum

Lines changed: 22 additions & 298 deletions
Large diffs are not rendered by default.

pkg/ping/dns.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ func (this *DnsPing) PingContext(ctx context.Context) IPingResult {
102102
if err != nil {
103103
return &DnsPingResult{0, err, nil}
104104
}
105-
if r == nil || r.Response == false || r.Opcode != dns.OpcodeQuery {
105+
if r == nil || !r.Response || r.Opcode != dns.OpcodeQuery {
106106
return &DnsPingResult{0, errors.New("response error"), nil}
107107
}
108-
return &DnsPingResult{int(time.Now().Sub(t0).Milliseconds()), nil, ip}
108+
109+
return &DnsPingResult{int(time.Since(t0).Milliseconds()), nil, ip}
109110
}
110111

111112
func NewDnsPing(host string, timeout time.Duration) *DnsPing {

pkg/ping/http.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"crypto/tls"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net"
99
"net/http"
1010
"net/url"
@@ -124,11 +124,11 @@ func (this *HttpPing) PingContext(ctx context.Context) IPingResult {
124124
return this.errorResult(err)
125125
}
126126
defer resp.Body.Close()
127-
body, err := ioutil.ReadAll(resp.Body)
127+
body, err := io.ReadAll(resp.Body)
128128
if err != nil {
129129
return this.errorResult(err)
130130
}
131-
return &HttpPingResult{int(time.Now().Sub(t0).Milliseconds()), resp.Proto, resp.StatusCode, len(body), nil, ip}
131+
return &HttpPingResult{int(time.Since(t0).Milliseconds()), resp.Proto, resp.StatusCode, len(body), nil, ip}
132132
}
133133

134134
func (this *HttpPing) errorResult(err error) *HttpPingResult {

pkg/ping/icmp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ func (this *IcmpPing) rawping(network string) IPingResult {
185185
}
186186
case 2:
187187
// destination unreachable
188-
return this.errorResult(errors.New(fmt.Sprintf("%s: destination unreachable", ip.String())))
188+
return this.errorResult(fmt.Errorf("%s: destination unreachable", ip.String()))
189189
case 3:
190190
// time exceeded
191-
return this.errorResult(errors.New(fmt.Sprintf("%s: time exceeded", ip.String())))
191+
return this.errorResult(fmt.Errorf("%s: time exceeded", ip.String()))
192192
}
193193
}
194194
}

0 commit comments

Comments
 (0)