Add linters and fix lint issues
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -28,7 +27,8 @@ func parseRoutingEntry(s string) (r routingEntry, err error) {
|
||||
return fmt.Errorf("line %q: %w", s, err)
|
||||
}
|
||||
fields := strings.Fields(s)
|
||||
if len(fields) < 11 {
|
||||
const minFields = 11
|
||||
if len(fields) < minFields {
|
||||
return r, wrapError(fmt.Errorf("not enough fields"))
|
||||
}
|
||||
r.iface = fields[0]
|
||||
@@ -74,20 +74,22 @@ func parseRoutingEntry(s string) (r routingEntry, err error) {
|
||||
|
||||
func reversedHexToIPv4(reversedHex string) (ip net.IP, err error) {
|
||||
bytes, err := hex.DecodeString(reversedHex)
|
||||
const nBytesRequired = 4
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse reversed IP hex %q: %s", reversedHex, err)
|
||||
} else if len(bytes) != 4 {
|
||||
return nil, fmt.Errorf("hex string contains %d bytes instead of 4", len(bytes))
|
||||
} else if L := len(bytes); L != nBytesRequired {
|
||||
return nil, fmt.Errorf("hex string contains %d bytes instead of %d", L, nBytesRequired)
|
||||
}
|
||||
return []byte{bytes[3], bytes[2], bytes[1], bytes[0]}, nil
|
||||
}
|
||||
|
||||
func hexToIPv4Mask(hexString string) (mask net.IPMask, err error) {
|
||||
bytes, err := hex.DecodeString(hexString)
|
||||
const nBytesRequired = 4
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse hex mask %q: %s", hexString, err)
|
||||
} else if len(bytes) != 4 {
|
||||
return nil, fmt.Errorf("hex string contains %d bytes instead of 4", len(bytes))
|
||||
} else if L := len(bytes); L != nBytesRequired {
|
||||
return nil, fmt.Errorf("hex string contains %d bytes instead of %d", L, nBytesRequired)
|
||||
}
|
||||
return []byte{bytes[3], bytes[2], bytes[1], bytes[0]}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user