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

13
ping.go
View File

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