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

Util function to transform string states #125

Open
martialblog opened this issue Dec 17, 2024 · 3 comments
Open

Util function to transform string states #125

martialblog opened this issue Dec 17, 2024 · 3 comments
Assignees

Comments

@martialblog
Copy link
Member

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?

@martialblog
Copy link
Member Author

@RincewindsHat What do you think?

@RincewindsHat
Copy link
Member

Funny you should mention that. Thought the same thing :-)

@RincewindsHat
Copy link
Member

So, yes. I think there is a place in the lib for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants