Skip to content

Commit ebd9eda

Browse files
update gude.go to avoid linter issues
*updates Copyright text *makes enums totally private *adds nolint to unavoidable JSON api variable name Signed-off-by: jonas loeffelholz <jonas.loeffelholz@9elements.com>
1 parent 4d7a9a0 commit ebd9eda

1 file changed

Lines changed: 33 additions & 27 deletions

File tree

pkg/module/pdu/gude.go

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// Copyright 2025 Blindspot Software
1+
// Copyright 2026 Blindspot Software
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// Package pdu provides a dutagent module that allows power control of a PDU via HTTP requests.
65
package pdu
76

87
import (
@@ -25,39 +24,46 @@ const (
2524
gudeResetCommand
2625
)
2726

28-
var gudecommandString = map[gudeCommands]string{
29-
gudeSwitchCommand: "1",
30-
gudeBatchModeCommand: "2",
31-
gudeResetCommand: "12",
32-
}
33-
3427
func (g gudeCommands) String() string {
35-
return gudecommandString[g]
28+
switch g {
29+
case gudeSwitchCommand:
30+
return "1"
31+
case gudeBatchModeCommand:
32+
return "2"
33+
case gudeResetCommand:
34+
return "12"
35+
default:
36+
return ""
37+
}
3638
}
3739

3840
type gudeState int
3941

4042
const (
41-
gudeStateOff gudeState = 0
42-
gudeStateOn gudeState = 1
43+
gudeStateOff gudeState = iota
44+
gudeStateOn
4345
)
4446

45-
var gudeStateString = map[gudeState]string{
46-
gudeStateOff: off,
47-
gudeStateOn: on,
48-
}
49-
5047
func (g gudeState) String() string {
51-
return gudeStateString[g]
52-
}
53-
54-
var gudeStateParameter = map[gudeState]string{
55-
gudeStateOff: "0",
56-
gudeStateOn: "1",
48+
switch g {
49+
case gudeStateOff:
50+
return off
51+
case gudeStateOn:
52+
return on
53+
default:
54+
return ""
55+
}
5756
}
5857

5958
func (g gudeState) getAPIParameter() string {
60-
return gudeStateParameter[g]
59+
switch g {
60+
case gudeStateOff:
61+
return "0"
62+
case gudeStateOn:
63+
return "1"
64+
default:
65+
return ""
66+
}
6167
}
6268

6369
func newGudeStateFromInt(state int) (gudeState, error) {
@@ -82,16 +88,16 @@ func newGudeStateFromString(state string) (gudeState, error) {
8288
}
8389
}
8490

85-
// gudeStateResponse represents the JSON response from Gude PDU status endpoint
91+
// gudeStateResponse represents the JSON response from Gude PDU status endpoint.
8692
type gudeStateResponse struct {
8793
Outputs []gudeOutput `json:"outputs"`
8894
}
8995

90-
// gudeOutput represents a single power output in the Gude PDU
96+
// gudeOutput represents a single power output in the Gude PDU.
9197
type gudeOutput struct {
9298
Name string `json:"name"`
93-
State int `json:"state"` // 0 = off, 1 = on
94-
SwCnt int `json:"sw_cnt"`
99+
State int `json:"state"` // 0 = off, 1 = on.
100+
SwCnt int `json:"sw_cnt"` //nolint:revive // JSON field name is defined by device API.
95101
Type int `json:"type"`
96102
Batch []int `json:"batch"`
97103
Wdog []any `json:"wdog"`

0 commit comments

Comments
 (0)