Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spelling + indentation #122

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5

- uses: actions/checkout@v4

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.54
version: v1.61
5 changes: 2 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
run:
timeout: 5m
tests: false
skip-files:
issues.exclude-files:
- 'testhelper/for_main.go'
issues:
exclude-rules:
Expand All @@ -16,7 +16,6 @@ linters:
disable:
- cyclop
- depguard
- exhaustivestruct
- exhaustruct
- forbidigo
- forcetypeassert
Expand All @@ -25,7 +24,7 @@ linters:
- gochecknoinits
- godox
- godot
- goerr113
- err113
- gofumpt
- gomnd
- lll
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func main() {

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

Expand Down
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *Config) ParseArray(arguments []string) {

if c.PrintVersion {
fmt.Println(c.Name, "version", c.Version)
BaseExit(3)
BaseExit(Unknown)
}

if c.DefaultHelper {
Expand Down Expand Up @@ -109,7 +109,7 @@ func LoadFromEnv(config interface{}) {
configValue := reflect.ValueOf(config).Elem()
configType := configValue.Type()

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

Expand All @@ -124,7 +124,7 @@ func LoadFromEnv(config interface{}) {
continue
}

// Potential for addding different types, for now we only use strings
// Potential for adding different types, for now we only use strings
// since the main use case is credentials
// nolint: exhaustive, gocritic
switch field.Type.Kind() {
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
module github.com/NETWAYS/go-check

go 1.14
go 1.22

require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
9 changes: 0 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions perfdata/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var replacer = strings.NewReplacer("=", "_", "`", "_", "'", "_", "\"", "_")
// formatNumeric returns a string representation of various possible numerics
//
// This supports most internal types of Go and all fmt.Stringer interfaces.
// Returns an eror in some known cases where the value of a data type does not
// Returns an error in some known cases where the value of a data type does not
// represent a valid measurement, e.g INF for floats
// This error can probably ignored in most cases and the perfdata point omitted,
// but silently dropping the value and returning the empty strings seems like bad style
Expand Down Expand Up @@ -78,7 +78,7 @@ func (p Perfdata) String() string {
}

// ValidatedString returns the proper format for the plugin output
// Returns an eror in some known cases where the value of a data type does not
// Returns an error in some known cases where the value of a data type does not
// represent a valid measurement, see the explanation for "formatNumeric" for
// perfdata values.
func (p Perfdata) ValidatedString() (string, error) {
Expand Down
85 changes: 44 additions & 41 deletions result/overall.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ package result
import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/NETWAYS/go-check"
"github.com/NETWAYS/go-check/perfdata"
)

// Overall is a singleton for a monitoring pluging that has several partial results (or sub-results)
const indentationOffset = 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a comment with a description


// Overall is a singleton for a monitoring plugin that has several partial results (or sub-results)
//
// Design decisions: A check plugin has a single Overall (singleton),
// each partial thing which is tested, gets its own subcheck.
Expand Down Expand Up @@ -98,53 +101,53 @@ func (o *Overall) GetStatus() int {
return check.Warning
} else if o.oks > 0 {
return check.OK
} else {
return check.Unknown
}
} else {
// state not set explicitly!
if len(o.PartialResults) == 0 {
return check.Unknown
}

var (
criticals int
warnings int
oks int
unknowns int
)
return check.Unknown
}

for _, sc := range o.PartialResults {
switch sc.GetStatus() {
case check.Critical:
criticals++
case check.Warning:
warnings++
case check.Unknown:
unknowns++
case check.OK:
oks++
}
}
// state not set explicitly!
if len(o.PartialResults) == 0 {
return check.Unknown
}

if criticals > 0 {
return check.Critical
var (
criticals int
warnings int
oks int
unknowns int
)

for _, sc := range o.PartialResults {
switch sc.GetStatus() {
case check.Critical:
criticals++
case check.Warning:
warnings++
case check.Unknown:
unknowns++
case check.OK:
oks++
}
}

if unknowns > 0 {
return check.Unknown
}
if criticals > 0 {
return check.Critical
}

if warnings > 0 {
return check.Warning
}
if unknowns > 0 {
return check.Unknown
}

if oks > 0 {
return check.OK
}
if warnings > 0 {
return check.Warning
}

return check.Unknown
if oks > 0 {
return check.OK
}

return check.Unknown
}

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

if s.PartialResults != nil {
for _, ss := range s.PartialResults {
output.WriteString(ss.getOutput(indentLevel + 2))
output.WriteString(ss.getOutput(indentLevel + indentationOffset))
}
}

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

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

s.state = state
Expand Down
Loading