Skip to content

Util function to transform string states #125

Open
@martialblog

Description

@martialblog

Sometimes there's a need for this util function:

func convertStateToInt(state string) (int, error) {
	state = strings.ToUpper(state)
	switch state {
	case "OK", "0":
		return check.OK, nil
	case "WARNING", "1":
		return check.Warning, nil
	case "CRITICAL", "2":
		return check.Critical, nil
	case "UNKNOWN", "3":
		return check.Unknown, nil
	default:
		return check.Unknown, errors.New("invalid state")
	}
}

For example when providing a state via a CLI flag.

See:

Should we maybe provide this in the go-check lib?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions