Skip to content

Commit

Permalink
更新依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
wzv5 committed Apr 20, 2023
1 parent f82cc55 commit 091d6e0
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 358 deletions.
39 changes: 39 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
dir: cmd/pping
goos:
- linux
- darwin
- windows
goarch:
- "386"
- amd64
ignore:
- goos: darwin
goarch: "386"
archives:
- name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums.txt"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- Merge pull request
- Merge branch
37 changes: 0 additions & 37 deletions .goreleaser.yml

This file was deleted.

7 changes: 3 additions & 4 deletions cmd/pping/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import (
var rootCmd *cobra.Command

var Version string
var PingError error = errors.New("ping error")
var ErrPing error = errors.New("ping error")

type globalFlags struct {
v bool
t bool
n int
i time.Duration
Expand Down Expand Up @@ -62,7 +61,7 @@ func init() {
func Execute() error {
rootCmd.Version = Version
err := rootCmd.Execute()
if err != nil && err != PingError {
if err != nil && err != ErrPing {
rootCmd.PrintErrf("Error: %v\n", err)
}
return err
Expand Down Expand Up @@ -121,7 +120,7 @@ end:
s.print()
}
if s.sent == 0 || s.failed != 0 {
return PingError
return ErrPing
}
return nil
}
Expand Down
1 change: 0 additions & 1 deletion cmd/pping/cmd/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

type tcpFlags struct {
port uint16
timeout time.Duration
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/pping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
log.SetFlags(log.Ltime)
cmd.Version = version
err := cmd.Execute()
if err == cmd.PingError {
if err == cmd.ErrPing {
os.Exit(1)
} else if err != nil {
os.Exit(2)
Expand Down
16 changes: 12 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
module github.com/wzv5/pping

go 1.14
go 1.19

require (
github.com/miekg/dns v1.1.38
github.com/spf13/cobra v1.1.3
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
github.com/miekg/dns v1.1.53
github.com/spf13/cobra v1.7.0
golang.org/x/net v0.9.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/tools v0.8.0 // indirect
)
320 changes: 22 additions & 298 deletions go.sum

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pkg/ping/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ func (this *DnsPing) PingContext(ctx context.Context) IPingResult {
if err != nil {
return &DnsPingResult{0, err, nil}
}
if r == nil || r.Response == false || r.Opcode != dns.OpcodeQuery {
if r == nil || !r.Response || r.Opcode != dns.OpcodeQuery {
return &DnsPingResult{0, errors.New("response error"), nil}
}
return &DnsPingResult{int(time.Now().Sub(t0).Milliseconds()), nil, ip}

return &DnsPingResult{int(time.Since(t0).Milliseconds()), nil, ip}
}

func NewDnsPing(host string, timeout time.Duration) *DnsPing {
Expand Down
6 changes: 3 additions & 3 deletions pkg/ping/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -124,11 +124,11 @@ func (this *HttpPing) PingContext(ctx context.Context) IPingResult {
return this.errorResult(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return this.errorResult(err)
}
return &HttpPingResult{int(time.Now().Sub(t0).Milliseconds()), resp.Proto, resp.StatusCode, len(body), nil, ip}
return &HttpPingResult{int(time.Since(t0).Milliseconds()), resp.Proto, resp.StatusCode, len(body), nil, ip}
}

func (this *HttpPing) errorResult(err error) *HttpPingResult {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ping/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ func (this *IcmpPing) rawping(network string) IPingResult {
}
case 2:
// destination unreachable
return this.errorResult(errors.New(fmt.Sprintf("%s: destination unreachable", ip.String())))
return this.errorResult(fmt.Errorf("%s: destination unreachable", ip.String()))
case 3:
// time exceeded
return this.errorResult(errors.New(fmt.Sprintf("%s: time exceeded", ip.String())))
return this.errorResult(fmt.Errorf("%s: time exceeded", ip.String()))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ping/icmp_other.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !windows,!linux,!darwin
//go:build !windows && !linux && !darwin

package ping

Expand Down
2 changes: 1 addition & 1 deletion pkg/ping/icmp_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux darwin
//go:build linux || darwin

package ping

Expand Down
6 changes: 3 additions & 3 deletions pkg/ping/icmp_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows
//go:build windows

package ping

Expand Down Expand Up @@ -80,7 +80,7 @@ func (this *IcmpPing) ping_rootless(ctx context.Context) IPingResult {
recvmsg := (*icmpv6_echo_reply)(unsafe.Pointer(&recv[0]))
var ip net.IP = recvmsg.address.sin6_addr[:]
if recvmsg.status != 0 {
return this.errorResult(errors.New(fmt.Sprintf("%s: %s", ip.String(), icmpStatusToString(recvmsg.status))))
return this.errorResult(fmt.Errorf("%s: %s", ip.String(), icmpStatusToString(recvmsg.status)))
}
return &IcmpPingResult{
Time: int(recvmsg.roundtriptime),
Expand All @@ -100,7 +100,7 @@ func (this *IcmpPing) ping_rootless(ctx context.Context) IPingResult {
recvmsg := (*icmp_echo_reply)(unsafe.Pointer(&recv[0]))
var ip net.IP = recvmsg.address[:]
if recvmsg.status != 0 {
return this.errorResult(errors.New(fmt.Sprintf("%s: %s", ip.String(), icmpStatusToString(recvmsg.status))))
return this.errorResult(fmt.Errorf("%s: %s", ip.String(), icmpStatusToString(recvmsg.status)))
}
return &IcmpPingResult{
Time: int(recvmsg.roundtriptime),
Expand Down
2 changes: 1 addition & 1 deletion pkg/ping/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (this *TcpPing) PingContext(ctx context.Context) IPingResult {
return &TcpPingResult{0, err, nil}
}
defer conn.Close()
return &TcpPingResult{int(time.Now().Sub(t0).Milliseconds()), nil, ip}
return &TcpPingResult{int(time.Since(t0).Milliseconds()), nil, ip}
}

func NewTcpPing(host string, port uint16, timeout time.Duration) *TcpPing {
Expand Down
1 change: 1 addition & 0 deletions staticcheck.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checks = ["inherit", "-ST1006"]

0 comments on commit 091d6e0

Please sign in to comment.