Add helper function to transform string states into int states#126
Add helper function to transform string states into int states#126martialblog wants to merge 1 commit intomainfrom
Conversation
|
Do we gain anything from a custom Int type? type Status int
// String returns the string corresponding to a state
func (s Status) String() string {
switch s {
case OK:
return OKString
case Warning:
return WarningString
case Critical:
return CriticalString
case Unknown:
}
return UnknownString
}
// NewStatusFromString returns a state corresponding to its
// common string representation
func NewStatusFromString(status string) Status {
... |
|
The thought of a Status type has occured to me and I do tend to like it, since the Therefore I am for introducing a specific |
| case UnknownString, "3": | ||
| return Unknown | ||
| default: | ||
| return Unknown |
There was a problem hiding this comment.
I do understand the wish for consistency, but IMHO there is a clear error case here and I feel uncomfortable with the function handling this the way it is now.
I think I would be rather (unpleasantly) surprised to find out, that this function transforms "Critiacl" (a typo of "Critical") to Unknown without giving me a way to verify it.
And yes, the function is rather trivial and I might be heavily prone to overengineering.
This PR adds a helper function to transform string states into int states.
It's the invert of the existing
StatusText.Unsure if this should should return an error if "invalid input" is given, the
StatusIntdoesn't so I decided to go for consistency.While writing this, I thought: is there a reason we don't have a "Status" type with these methods attached? 🤔
See #125