Skip to content

Commit e9c2451

Browse files
RincewindsHatRincewindsHat
and
RincewindsHat
authored
Fix spelling + indentation (#122)
* Fix spelling + indentation * Update linter config * Go to go 1.22 and run go mod tidy * Fix linter issues * Bump linter version in github runner config * Try to explain indentationOffset a bit --------- Co-authored-by: RincewindsHat <[email protected]>
1 parent 557d6fd commit e9c2451

File tree

8 files changed

+62
-65
lines changed

8 files changed

+62
-65
lines changed

.github/workflows/golangci-lint.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ jobs:
1010
name: lint
1111
runs-on: ubuntu-latest
1212
steps:
13-
- name: Set up Go
14-
uses: actions/setup-go@v5
15-
1613
- uses: actions/checkout@v4
1714

1815
- name: golangci-lint
1916
uses: golangci/golangci-lint-action@v6
2017
with:
21-
version: v1.54
18+
version: v1.61

.golangci.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
run:
22
timeout: 5m
33
tests: false
4-
skip-files:
4+
issues.exclude-files:
55
- 'testhelper/for_main.go'
66
issues:
77
exclude-rules:
@@ -16,7 +16,6 @@ linters:
1616
disable:
1717
- cyclop
1818
- depguard
19-
- exhaustivestruct
2019
- exhaustruct
2120
- forbidigo
2221
- forcetypeassert
@@ -25,7 +24,7 @@ linters:
2524
- gochecknoinits
2625
- godox
2726
- godot
28-
- goerr113
27+
- err113
2928
- gofumpt
3029
- gomnd
3130
- lll

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func main() {
3434

3535
// Some checking should be done here, when --help is not passed
3636
check.Exitf(check.OK, "Everything is fine - answer=%d", 42)
37-
// Output:
38-
// OK - Everything is fine - answer=42
37+
// Output:
38+
// OK - Everything is fine - answer=42
3939
}
4040
```
4141

config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *Config) ParseArray(arguments []string) {
8181

8282
if c.PrintVersion {
8383
fmt.Println(c.Name, "version", c.Version)
84-
BaseExit(3)
84+
BaseExit(Unknown)
8585
}
8686

8787
if c.DefaultHelper {
@@ -109,7 +109,7 @@ func LoadFromEnv(config interface{}) {
109109
configValue := reflect.ValueOf(config).Elem()
110110
configType := configValue.Type()
111111

112-
for i := 0; i < configValue.NumField(); i++ {
112+
for i := range configValue.NumField() {
113113
field := configType.Field(i)
114114
tag := field.Tag.Get("env")
115115

@@ -124,7 +124,7 @@ func LoadFromEnv(config interface{}) {
124124
continue
125125
}
126126

127-
// Potential for addding different types, for now we only use strings
127+
// Potential for adding different types, for now we only use strings
128128
// since the main use case is credentials
129129
// nolint: exhaustive, gocritic
130130
switch field.Type.Kind() {

go.mod

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
module github.com/NETWAYS/go-check
22

3-
go 1.14
3+
go 1.22
44

55
require (
66
github.com/spf13/pflag v1.0.5
77
github.com/stretchr/testify v1.9.0
88
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
gopkg.in/yaml.v3 v3.0.1 // indirect
14+
)

go.sum

-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
32
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
43
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
54
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
65
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
76
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
8-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
10-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
11-
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
12-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
13-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
14-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
157
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
168
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
179
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1810
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2011
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2112
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

perfdata/type.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var replacer = strings.NewReplacer("=", "_", "`", "_", "'", "_", "\"", "_")
1515
// formatNumeric returns a string representation of various possible numerics
1616
//
1717
// This supports most internal types of Go and all fmt.Stringer interfaces.
18-
// Returns an eror in some known cases where the value of a data type does not
18+
// Returns an error in some known cases where the value of a data type does not
1919
// represent a valid measurement, e.g INF for floats
2020
// This error can probably ignored in most cases and the perfdata point omitted,
2121
// but silently dropping the value and returning the empty strings seems like bad style
@@ -78,7 +78,7 @@ func (p Perfdata) String() string {
7878
}
7979

8080
// ValidatedString returns the proper format for the plugin output
81-
// Returns an eror in some known cases where the value of a data type does not
81+
// Returns an error in some known cases where the value of a data type does not
8282
// represent a valid measurement, see the explanation for "formatNumeric" for
8383
// perfdata values.
8484
func (p Perfdata) ValidatedString() (string, error) {

result/overall.go

+45-41
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ package result
44
import (
55
"errors"
66
"fmt"
7+
"strconv"
78
"strings"
89

910
"github.com/NETWAYS/go-check"
1011
"github.com/NETWAYS/go-check/perfdata"
1112
)
1213

13-
// Overall is a singleton for a monitoring pluging that has several partial results (or sub-results)
14+
// The "width" of the indentation which is added on every level
15+
const indentationOffset = 2
16+
17+
// Overall is a singleton for a monitoring plugin that has several partial results (or sub-results)
1418
//
1519
// Design decisions: A check plugin has a single Overall (singleton),
1620
// each partial thing which is tested, gets its own subcheck.
@@ -98,53 +102,53 @@ func (o *Overall) GetStatus() int {
98102
return check.Warning
99103
} else if o.oks > 0 {
100104
return check.OK
101-
} else {
102-
return check.Unknown
103-
}
104-
} else {
105-
// state not set explicitly!
106-
if len(o.PartialResults) == 0 {
107-
return check.Unknown
108105
}
109106

110-
var (
111-
criticals int
112-
warnings int
113-
oks int
114-
unknowns int
115-
)
107+
return check.Unknown
108+
}
116109

117-
for _, sc := range o.PartialResults {
118-
switch sc.GetStatus() {
119-
case check.Critical:
120-
criticals++
121-
case check.Warning:
122-
warnings++
123-
case check.Unknown:
124-
unknowns++
125-
case check.OK:
126-
oks++
127-
}
128-
}
110+
// state not set explicitly!
111+
if len(o.PartialResults) == 0 {
112+
return check.Unknown
113+
}
129114

130-
if criticals > 0 {
131-
return check.Critical
115+
var (
116+
criticals int
117+
warnings int
118+
oks int
119+
unknowns int
120+
)
121+
122+
for _, sc := range o.PartialResults {
123+
switch sc.GetStatus() {
124+
case check.Critical:
125+
criticals++
126+
case check.Warning:
127+
warnings++
128+
case check.Unknown:
129+
unknowns++
130+
case check.OK:
131+
oks++
132132
}
133+
}
133134

134-
if unknowns > 0 {
135-
return check.Unknown
136-
}
135+
if criticals > 0 {
136+
return check.Critical
137+
}
137138

138-
if warnings > 0 {
139-
return check.Warning
140-
}
139+
if unknowns > 0 {
140+
return check.Unknown
141+
}
141142

142-
if oks > 0 {
143-
return check.OK
144-
}
143+
if warnings > 0 {
144+
return check.Warning
145+
}
145146

146-
return check.Unknown
147+
if oks > 0 {
148+
return check.OK
147149
}
150+
151+
return check.Unknown
148152
}
149153

150154
// GetSummary returns a text representation of the current state of the Overall
@@ -284,7 +288,7 @@ func (s *PartialResult) getOutput(indentLevel int) string {
284288

285289
if s.PartialResults != nil {
286290
for _, ss := range s.PartialResults {
287-
output.WriteString(ss.getOutput(indentLevel + 2))
291+
output.WriteString(ss.getOutput(indentLevel + indentationOffset))
288292
}
289293
}
290294

@@ -294,7 +298,7 @@ func (s *PartialResult) getOutput(indentLevel int) string {
294298
// SetDefaultState sets a new default state for a PartialResult
295299
func (s *PartialResult) SetDefaultState(state int) error {
296300
if state < check.OK || state > check.Unknown {
297-
return errors.New("Default State is not a valid result state. Got " + fmt.Sprint(state) + " which is not valid")
301+
return errors.New("Default State is not a valid result state. Got " + strconv.Itoa(state) + " which is not valid")
298302
}
299303

300304
s.defaultState = state
@@ -306,7 +310,7 @@ func (s *PartialResult) SetDefaultState(state int) error {
306310
// SetState sets a state for a PartialResult
307311
func (s *PartialResult) SetState(state int) error {
308312
if state < check.OK || state > check.Unknown {
309-
return errors.New("Default State is not a valid result state. Got " + fmt.Sprint(state) + " which is not valid")
313+
return errors.New("Default State is not a valid result state. Got " + strconv.Itoa(state) + " which is not valid")
310314
}
311315

312316
s.state = state

0 commit comments

Comments
 (0)