Skip to content

Commit 56324fb

Browse files
authored
Merge pull request #127 from NETWAYS/gofix
Apply go fix
2 parents 203eea1 + 6d599dc commit 56324fb

8 files changed

Lines changed: 27 additions & 29 deletions

File tree

hp/cntlr/controllers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (t *CpqDaCntlrTable) ListIds() []string {
2424
return t.Snmp.GetSortedOIDs()
2525
}
2626

27-
func (t *CpqDaCntlrTable) GetValue(id string, oid string) (interface{}, error) {
27+
func (t *CpqDaCntlrTable) GetValue(id string, oid string) (any, error) {
2828
return t.Snmp.GetValue(id, oid)
2929
}
3030

hp/cntlr/firmware_data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package cntlr
55
// Effective date: 2020-04-06
66

77
// Note: Always validate IsAffected() when changing values here!!
8+
89
const VersionAffectedRaid1 = "2.62"
910

1011
var VersionAffectedRaid5 = []string{"1.98", "1.99", "2.02", "2.03"}

hp/drive/drives.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (t *CpqDaPhyDrvTable) ListIds() []string {
2424
return t.Snmp.GetSortedOIDs()
2525
}
2626

27-
func (t *CpqDaPhyDrvTable) GetValue(id string, oid string) (interface{}, error) {
27+
func (t *CpqDaPhyDrvTable) GetValue(id string, oid string) (any, error) {
2828
return t.Snmp.GetValue(id, oid)
2929
}
3030

hp/ilo/firmware.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func GetIloInformation(client gosnmp.Handler) (ilo *Ilo, err error) {
2626
ilo = &Ilo{}
2727

2828
iloVariables, err := client.Get(oids)
29-
3029
if err != nil {
3130
err = fmt.Errorf("could not get SNMP data for iLO: %w", err)
3231
return

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ func main() {
139139

140140
// Extract controller data from SNMP Table
141141
controllers, err := cntlr.GetControllersFromTable(cntlrTable)
142-
143142
if err != nil {
144143
check.ExitError(err)
145144
}

snmp/file_handler.go

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@ package snmp
33
import (
44
"fmt"
55
"io"
6+
"maps"
67
"os"
78

89
"github.com/gosnmp/gosnmp"
910
)
1011

11-
// Provides a GoSNMP like data interface, but with data from a snmpwalk output
12+
// FileHandler provides a GoSNMP like data interface, but with data from a snmpwalk output
1213
//
1314
// Anyone can generate an output by running:
1415
//
1516
// snmpwalk -c public -v2c -On HOST .1.3.6.1 >snmp-data.txt
1617
//
1718
// Warning: This does not implement all functions of gosnmp.Handler
1819
type FileHandler struct {
19-
Data WalkData
20-
2120
gosnmp.Handler
21+
22+
Data WalkData
2223
}
2324

24-
// Create a new file handler and initialize it with data from an io.Reader
25+
// NewFileHandler creates a new file handler and initialize it with data from an io.Reader
2526
func NewFileHandler(r io.Reader) (h *FileHandler, err error) {
2627
h = &FileHandler{}
2728
err = h.ReadFromWalk(r)
2829

2930
return
3031
}
3132

32-
// Create a new file handler and initialize it with data by reading from a file
33+
// NewFileHandlerFromFile creates a new file handler and initialize it with data by reading from a file
3334
func NewFileHandlerFromFile(filePath string) (h *FileHandler, err error) {
3435
fh, err := os.Open(filePath)
3536
if err != nil {
@@ -42,7 +43,7 @@ func NewFileHandlerFromFile(filePath string) (h *FileHandler, err error) {
4243
return NewFileHandler(fh)
4344
}
4445

45-
// Read data from a io.Reader and parse it for PDUs
46+
// ReadFromWalk reads data from a io.Reader and parse it for PDUs
4647
//
4748
// They will be stored in Data for later use.
4849
func (h *FileHandler) ReadFromWalk(r io.Reader) error {
@@ -55,34 +56,32 @@ func (h *FileHandler) ReadFromWalk(r io.Reader) error {
5556
return err
5657
}
5758

58-
for k, v := range pduList {
59-
h.Data[k] = v
60-
}
59+
maps.Copy(h.Data, pduList)
6160

6261
return nil
6362
}
6463

65-
// Simulate Connect behavior by returning no error
64+
// Connect simulates Connect behavior by returning no error
6665
func (h *FileHandler) Connect() error {
6766
return nil
6867
}
6968

70-
// Simulate ConnectIPv4 behavior by returning no error
69+
// ConnectIPv4 simulates ConnectIPv4 behavior by returning no error
7170
func (h *FileHandler) ConnectIPv4() error {
7271
return nil
7372
}
7473

75-
// Simulate ConnectIPv6 behavior by returning no error
74+
// ConnectIPv6 simulates ConnectIPv6 behavior by returning no error
7675
func (h *FileHandler) ConnectIPv6() error {
7776
return nil
7877
}
7978

80-
// Simulate Close behavior by returning no error
79+
// Close simulates Close behavior by returning no error
8180
func (h *FileHandler) Close() error {
8281
return nil
8382
}
8483

85-
// Simulating Get() behavior by searching read in data
84+
// Get simulates Get() behavior by searching read in data
8685
func (h *FileHandler) Get(oids []string) (result *gosnmp.SnmpPacket, err error) {
8786
result = &gosnmp.SnmpPacket{
8887
Version: gosnmp.Version2c,
@@ -102,18 +101,18 @@ func (h *FileHandler) Get(oids []string) (result *gosnmp.SnmpPacket, err error)
102101
return
103102
}
104103

105-
// Not yet implemented
104+
// GetBulk is not yet implemented
106105
func (h *FileHandler) GetBulk(oids []string, nonRepeaters uint8,
107106
maxRepetitions uint32) (result *gosnmp.SnmpPacket, err error) {
108107
panic("not implemented")
109108
}
110109

111-
// Not yet implemented
110+
// GetNext is not yet implemented
112111
func (h *FileHandler) GetNext(oids []string) (result *gosnmp.SnmpPacket, err error) {
113112
panic("not implemented")
114113
}
115114

116-
// Simulating Walk() behavior by searching read in data
115+
// Walk simulates Walk() behavior by searching read in data
117116
func (h *FileHandler) Walk(rootOid string, walkFn gosnmp.WalkFunc) (err error) {
118117
rootOid, err = EnsureValidOid(rootOid)
119118
if err != nil {
@@ -134,17 +133,17 @@ func (h *FileHandler) Walk(rootOid string, walkFn gosnmp.WalkFunc) (err error) {
134133
return
135134
}
136135

137-
// Not yet implemented
136+
// WalkAll is not yet implemented
138137
func (h *FileHandler) WalkAll(rootOid string) (results []gosnmp.SnmpPDU, err error) {
139138
panic("not implemented")
140139
}
141140

142-
// Not yet implemented
141+
// BulkWalk is not yet implemented
143142
func (h *FileHandler) BulkWalk(rootOid string, walkFn gosnmp.WalkFunc) error {
144143
panic("not implemented")
145144
}
146145

147-
// Not yet implemented
146+
// BulkWalkAll is not yet implemented
148147
func (h *FileHandler) BulkWalkAll(rootOid string) (results []gosnmp.SnmpPDU, err error) {
149148
panic("not implemented")
150149
}

snmp/snmpwalk.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func ParseWalkLine(line string) (pdu *gosnmp.SnmpPDU, err error) {
146146
return
147147
}
148148

149-
// Test if an OID is in a valid format like `.1.23.456`
149+
// IsValidOid tests whether an OID is in a valid format like `.1.23.456`
150150
func IsValidOid(oid string) error {
151151
if len(oid) == 0 {
152152
return fmt.Errorf("oid is empty")
@@ -168,8 +168,7 @@ func IsValidOid(oid string) error {
168168
return nil
169169
}
170170

171-
// Test an OID, but prefix a missing dot
172-
//
171+
// EnsureValidOid tests whether an OID is valid, but prefix a missing dot
173172
// Useful to be compatible with the base implementation of SNMP, where it is optional.
174173
func EnsureValidOid(oid string) (string, error) {
175174
if oid[0] != '.' {

snmp/table.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ func (t *Table) Reset() {
2828
func (t *Table) Walk() error {
2929
t.Reset()
3030

31-
if err := t.Client.Walk(t.Oid, t.addWalkValue); err != nil {
31+
err := t.Client.Walk(t.Oid, t.addWalkValue)
32+
if err != nil {
3233
return err
3334
}
3435

@@ -39,7 +40,7 @@ func (t *Table) Walk() error {
3940
return nil
4041
}
4142

42-
func (t *Table) GetValue(id string, oid string) (interface{}, error) {
43+
func (t *Table) GetValue(id string, oid string) (any, error) {
4344
parts := strings.Split(oid, ".")
4445
column := parts[len(parts)-1]
4546

0 commit comments

Comments
 (0)