Merge pull request #355 from sean-/fix-lint-errors

Fix lint errors
pull/359/head
shirou 8 years ago committed by GitHub
commit c251591dc7

@ -27,7 +27,7 @@ import (
var ( var (
Timeout = 3 * time.Second Timeout = 3 * time.Second
ErrTimeout = errors.New("Command timed out.") ErrTimeout = errors.New("command timed out")
) )
type Invoker interface { type Invoker interface {

@ -18,7 +18,7 @@ var (
const endOfLine = "\n" const endOfLine = "\n"
func parseNetstatLine(line string) (stat *IOCountersStat, linkId *uint, err error) { func parseNetstatLine(line string) (stat *IOCountersStat, linkID *uint, err error) {
var ( var (
numericValue uint64 numericValue uint64
columns = strings.Fields(line) columns = strings.Fields(line)
@ -35,8 +35,8 @@ func parseNetstatLine(line string) (stat *IOCountersStat, linkId *uint, err erro
if err != nil { if err != nil {
return return
} }
linkIdUint := uint(numericValue) linkIDUint := uint(numericValue)
linkId = &linkIdUint linkID = &linkIDUint
} }
base := 1 base := 1
@ -91,7 +91,7 @@ func parseNetstatLine(line string) (stat *IOCountersStat, linkId *uint, err erro
} }
type netstatInterface struct { type netstatInterface struct {
linkId *uint linkID *uint
stat *IOCountersStat stat *IOCountersStat
} }
@ -112,7 +112,7 @@ func parseNetstatOutput(output string) ([]netstatInterface, error) {
for index := 0; index < numberInterfaces; index++ { for index := 0; index < numberInterfaces; index++ {
nsIface := netstatInterface{} nsIface := netstatInterface{}
if nsIface.stat, nsIface.linkId, err = parseNetstatLine(lines[index+1]); err != nil { if nsIface.stat, nsIface.linkID, err = parseNetstatLine(lines[index+1]); err != nil {
return nil, err return nil, err
} }
interfaces[index] = nsIface interfaces[index] = nsIface
@ -126,7 +126,7 @@ type mapInterfaceNameUsage map[string]uint
func newMapInterfaceNameUsage(ifaces []netstatInterface) mapInterfaceNameUsage { func newMapInterfaceNameUsage(ifaces []netstatInterface) mapInterfaceNameUsage {
output := make(mapInterfaceNameUsage) output := make(mapInterfaceNameUsage)
for index := range ifaces { for index := range ifaces {
if ifaces[index].linkId != nil { if ifaces[index].linkID != nil {
ifaceName := ifaces[index].stat.Name ifaceName := ifaces[index].stat.Name
usage, ok := output[ifaceName] usage, ok := output[ifaceName]
if ok { if ok {
@ -192,7 +192,7 @@ func IOCounters(pernic bool) ([]IOCountersStat, error) {
if !ifaceUsage.isTruncated() { if !ifaceUsage.isTruncated() {
// no truncated interface name, return stats of all interface with <Link#...> // no truncated interface name, return stats of all interface with <Link#...>
for index := range nsInterfaces { for index := range nsInterfaces {
if nsInterfaces[index].linkId != nil { if nsInterfaces[index].linkID != nil {
ret[retIndex] = *nsInterfaces[index].stat ret[retIndex] = *nsInterfaces[index].stat
retIndex++ retIndex++
} }
@ -212,7 +212,7 @@ func IOCounters(pernic bool) ([]IOCountersStat, error) {
for _, interfaceName := range interfaceNames { for _, interfaceName := range interfaceNames {
truncated := true truncated := true
for index := range nsInterfaces { for index := range nsInterfaces {
if nsInterfaces[index].linkId != nil && nsInterfaces[index].stat.Name == interfaceName { if nsInterfaces[index].linkID != nil && nsInterfaces[index].stat.Name == interfaceName {
// handle the non truncated name to avoid execute netstat for them again // handle the non truncated name to avoid execute netstat for them again
ret[retIndex] = *nsInterfaces[index].stat ret[retIndex] = *nsInterfaces[index].stat
retIndex++ retIndex++
@ -234,7 +234,7 @@ func IOCounters(pernic bool) ([]IOCountersStat, error) {
continue continue
} }
for index := range parsedIfaces { for index := range parsedIfaces {
if parsedIfaces[index].linkId != nil { if parsedIfaces[index].linkID != nil {
ret = append(ret, *parsedIfaces[index].stat) ret = append(ret, *parsedIfaces[index].stat)
break break
} }

@ -49,28 +49,28 @@ func assertLoopbackStat(t *testing.T, err error, stat *IOCountersStat) {
} }
func TestparseNetstatLineLink(t *testing.T) { func TestparseNetstatLineLink(t *testing.T) {
stat, linkId, err := parseNetstatLine( stat, linkID, err := parseNetstatLine(
`lo0 16384 <Link#1> 869107 0 169411755 869108 1 169411756 0 0`, `lo0 16384 <Link#1> 869107 0 169411755 869108 1 169411756 0 0`,
) )
assertLoopbackStat(t, err, stat) assertLoopbackStat(t, err, stat)
assert.NotNil(t, linkId) assert.NotNil(t, linkID)
assert.Equal(t, uint(1), *linkId) assert.Equal(t, uint(1), *linkID)
} }
func TestparseNetstatLineIPv6(t *testing.T) { func TestparseNetstatLineIPv6(t *testing.T) {
stat, linkId, err := parseNetstatLine( stat, linkID, err := parseNetstatLine(
`lo0 16384 ::1/128 ::1 869107 - 169411755 869108 1 169411756 - -`, `lo0 16384 ::1/128 ::1 869107 - 169411755 869108 1 169411756 - -`,
) )
assertLoopbackStat(t, err, stat) assertLoopbackStat(t, err, stat)
assert.Nil(t, linkId) assert.Nil(t, linkID)
} }
func TestparseNetstatLineIPv4(t *testing.T) { func TestparseNetstatLineIPv4(t *testing.T) {
stat, linkId, err := parseNetstatLine( stat, linkID, err := parseNetstatLine(
`lo0 16384 127 127.0.0.1 869107 - 169411755 869108 1 169411756 - -`, `lo0 16384 127 127.0.0.1 869107 - 169411755 869108 1 169411756 - -`,
) )
assertLoopbackStat(t, err, stat) assertLoopbackStat(t, err, stat)
assert.Nil(t, linkId) assert.Nil(t, linkID)
} }
func TestParseNetstatOutput(t *testing.T) { func TestParseNetstatOutput(t *testing.T) {
@ -81,23 +81,23 @@ func TestParseNetstatOutput(t *testing.T) {
assert.NotNil(t, nsInterfaces[index].stat, "Index %d", index) assert.NotNil(t, nsInterfaces[index].stat, "Index %d", index)
} }
assert.NotNil(t, nsInterfaces[0].linkId) assert.NotNil(t, nsInterfaces[0].linkID)
assert.Equal(t, uint(1), *nsInterfaces[0].linkId) assert.Equal(t, uint(1), *nsInterfaces[0].linkID)
assert.Nil(t, nsInterfaces[1].linkId) assert.Nil(t, nsInterfaces[1].linkID)
assert.Nil(t, nsInterfaces[2].linkId) assert.Nil(t, nsInterfaces[2].linkID)
assert.Nil(t, nsInterfaces[3].linkId) assert.Nil(t, nsInterfaces[3].linkID)
assert.NotNil(t, nsInterfaces[4].linkId) assert.NotNil(t, nsInterfaces[4].linkID)
assert.Equal(t, uint(2), *nsInterfaces[4].linkId) assert.Equal(t, uint(2), *nsInterfaces[4].linkID)
assert.NotNil(t, nsInterfaces[5].linkId) assert.NotNil(t, nsInterfaces[5].linkID)
assert.Equal(t, uint(3), *nsInterfaces[5].linkId) assert.Equal(t, uint(3), *nsInterfaces[5].linkID)
assert.NotNil(t, nsInterfaces[6].linkId) assert.NotNil(t, nsInterfaces[6].linkID)
assert.Equal(t, uint(4), *nsInterfaces[6].linkId) assert.Equal(t, uint(4), *nsInterfaces[6].linkID)
assert.Nil(t, nsInterfaces[7].linkId) assert.Nil(t, nsInterfaces[7].linkID)
mapUsage := newMapInterfaceNameUsage(nsInterfaces) mapUsage := newMapInterfaceNameUsage(nsInterfaces)
assert.False(t, mapUsage.isTruncated()) assert.False(t, mapUsage.isTruncated())
@ -114,24 +114,24 @@ func TestParseNetstatTruncated(t *testing.T) {
const truncatedIface = "utun8" const truncatedIface = "utun8"
assert.NotNil(t, nsInterfaces[6].linkId) assert.NotNil(t, nsInterfaces[6].linkID)
assert.Equal(t, uint(88), *nsInterfaces[6].linkId) assert.Equal(t, uint(88), *nsInterfaces[6].linkID)
assert.Equal(t, truncatedIface, nsInterfaces[6].stat.Name) assert.Equal(t, truncatedIface, nsInterfaces[6].stat.Name)
assert.NotNil(t, nsInterfaces[7].linkId) assert.NotNil(t, nsInterfaces[7].linkID)
assert.Equal(t, uint(90), *nsInterfaces[7].linkId) assert.Equal(t, uint(90), *nsInterfaces[7].linkID)
assert.Equal(t, truncatedIface, nsInterfaces[7].stat.Name) assert.Equal(t, truncatedIface, nsInterfaces[7].stat.Name)
assert.NotNil(t, nsInterfaces[8].linkId) assert.NotNil(t, nsInterfaces[8].linkID)
assert.Equal(t, uint(92), *nsInterfaces[8].linkId) assert.Equal(t, uint(92), *nsInterfaces[8].linkID)
assert.Equal(t, truncatedIface, nsInterfaces[8].stat.Name) assert.Equal(t, truncatedIface, nsInterfaces[8].stat.Name)
assert.NotNil(t, nsInterfaces[9].linkId) assert.NotNil(t, nsInterfaces[9].linkID)
assert.Equal(t, uint(93), *nsInterfaces[9].linkId) assert.Equal(t, uint(93), *nsInterfaces[9].linkID)
assert.Equal(t, truncatedIface, nsInterfaces[9].stat.Name) assert.Equal(t, truncatedIface, nsInterfaces[9].stat.Name)
assert.NotNil(t, nsInterfaces[10].linkId) assert.NotNil(t, nsInterfaces[10].linkID)
assert.Equal(t, uint(95), *nsInterfaces[10].linkId) assert.Equal(t, uint(95), *nsInterfaces[10].linkID)
assert.Equal(t, truncatedIface, nsInterfaces[10].stat.Name) assert.Equal(t, truncatedIface, nsInterfaces[10].stat.Name)
mapUsage := newMapInterfaceNameUsage(nsInterfaces) mapUsage := newMapInterfaceNameUsage(nsInterfaces)

@ -261,17 +261,17 @@ var kindUNIX = netConnectionKindType{
} }
var netConnectionKindMap = map[string][]netConnectionKindType{ var netConnectionKindMap = map[string][]netConnectionKindType{
"all": []netConnectionKindType{kindTCP4, kindTCP6, kindUDP4, kindUDP6, kindUNIX}, "all": {kindTCP4, kindTCP6, kindUDP4, kindUDP6, kindUNIX},
"tcp": []netConnectionKindType{kindTCP4, kindTCP6}, "tcp": {kindTCP4, kindTCP6},
"tcp4": []netConnectionKindType{kindTCP4}, "tcp4": {kindTCP4},
"tcp6": []netConnectionKindType{kindTCP6}, "tcp6": {kindTCP6},
"udp": []netConnectionKindType{kindUDP4, kindUDP6}, "udp": {kindUDP4, kindUDP6},
"udp4": []netConnectionKindType{kindUDP4}, "udp4": {kindUDP4},
"udp6": []netConnectionKindType{kindUDP6}, "udp6": {kindUDP6},
"unix": []netConnectionKindType{kindUNIX}, "unix": {kindUNIX},
"inet": []netConnectionKindType{kindTCP4, kindTCP6, kindUDP4, kindUDP6}, "inet": {kindTCP4, kindTCP6, kindUDP4, kindUDP6},
"inet4": []netConnectionKindType{kindTCP4, kindUDP4}, "inet4": {kindTCP4, kindUDP4},
"inet6": []netConnectionKindType{kindTCP6, kindUDP6}, "inet6": {kindTCP6, kindUDP6},
} }
type inodeMap struct { type inodeMap struct {
@ -690,7 +690,7 @@ func processUnix(file string, kind netConnectionKindType, inodes map[string][]in
pairs, exists := inodes[inode] pairs, exists := inodes[inode]
if !exists { if !exists {
pairs = []inodeMap{ pairs = []inodeMap{
inodeMap{}, {},
} }
} }
for _, pair := range pairs { for _, pair := range pairs {

@ -118,25 +118,25 @@ func TestDecodeAddress(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
addr := map[string]AddrTest{ addr := map[string]AddrTest{
"0500000A:0016": AddrTest{ "0500000A:0016": {
IP: "10.0.0.5", IP: "10.0.0.5",
Port: 22, Port: 22,
}, },
"0100007F:D1C2": AddrTest{ "0100007F:D1C2": {
IP: "127.0.0.1", IP: "127.0.0.1",
Port: 53698, Port: 53698,
}, },
"11111:0035": AddrTest{ "11111:0035": {
Error: true, Error: true,
}, },
"0100007F:BLAH": AddrTest{ "0100007F:BLAH": {
Error: true, Error: true,
}, },
"0085002452100113070057A13F025401:0035": AddrTest{ "0085002452100113070057A13F025401:0035": {
IP: "2400:8500:1301:1052:a157:7:154:23f", IP: "2400:8500:1301:1052:a157:7:154:23f",
Port: 53, Port: 53,
}, },
"00855210011307F025401:0035": AddrTest{ "00855210011307F025401:0035": {
Error: true, Error: true,
}, },
} }

@ -97,12 +97,12 @@ func TestNetIOCountersPerNic(t *testing.T) {
func TestGetNetIOCountersAll(t *testing.T) { func TestGetNetIOCountersAll(t *testing.T) {
n := []IOCountersStat{ n := []IOCountersStat{
IOCountersStat{ {
Name: "a", Name: "a",
BytesRecv: 10, BytesRecv: 10,
PacketsRecv: 10, PacketsRecv: 10,
}, },
IOCountersStat{ {
Name: "b", Name: "b",
BytesRecv: 10, BytesRecv: 10,
PacketsRecv: 10, PacketsRecv: 10,

@ -152,7 +152,7 @@ func (p *Process) CreateTime() (int64, error) {
elapsedDurations = append(elapsedDurations, time.Duration(p)) elapsedDurations = append(elapsedDurations, time.Duration(p))
} }
var elapsed time.Duration = time.Duration(elapsedDurations[0]) * time.Second var elapsed = time.Duration(elapsedDurations[0]) * time.Second
if len(elapsedDurations) > 1 { if len(elapsedDurations) > 1 {
elapsed += time.Duration(elapsedDurations[1]) * time.Minute elapsed += time.Duration(elapsedDurations[1]) * time.Minute
} }

Loading…
Cancel
Save