Add golangci-lint configuration (#100)

* Add a configuration for golangci-lint.
* Fix some linter issues.

Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
Ben Kochie 2020-09-14 20:23:32 +02:00 committed by GitHub
parent 800dd84e47
commit e11dda7fa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

6
.golangci.yml Normal file
View File

@ -0,0 +1,6 @@
---
issues:
exclude-rules:
- path: _test.go
linters:
- errcheck

View File

@ -39,7 +39,7 @@ func main() {
count := flag.Int("c", -1, "")
privileged := flag.Bool("privileged", false, "")
flag.Usage = func() {
fmt.Printf(usage)
fmt.Print(usage)
}
flag.Parse()
@ -59,7 +59,7 @@ func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for _ = range c {
for range c {
pinger.Stop()
}
}()

13
ping.go
View File

@ -145,7 +145,6 @@ type Pinger struct {
addr string
ipv4 bool
size int
id int
sequence int
// network is one of "ip", "ip4", or "ip6".
@ -309,12 +308,16 @@ func (p *Pinger) Run() {
if conn = p.listen(ipv4Proto[p.protocol]); conn == nil {
return
}
conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true)
if conn.IPv4PacketConn().SetControlMessage(ipv4.FlagTTL, true) != nil {
return
}
} else {
if conn = p.listen(ipv6Proto[p.protocol]); conn == nil {
return
}
conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true)
if conn.IPv6PacketConn().SetControlMessage(ipv6.FlagHopLimit, true) != nil {
return
}
}
defer conn.Close()
defer p.finish()
@ -431,7 +434,9 @@ func (p *Pinger) recvICMP(
return
default:
bytes := make([]byte, 512)
conn.SetReadDeadline(time.Now().Add(time.Millisecond * 100))
if conn.SetReadDeadline(time.Now().Add(time.Millisecond * 100)) != nil {
return
}
var n, ttl int
var err error
if p.ipv4 {