types: drop custom JSON marshalling for Status

Keep Status as a plain integer on the wire so that OpenAPI/swaggo
can generate correct enum definitions without needing to handle
the custom string encoding.  The String() method is preserved for
logging and debugging.
This commit is contained in:
nemunaire 2026-04-11 17:21:07 +07:00
commit 2cd323beed

View file

@ -192,46 +192,6 @@ func (s Status) String() string {
}
}
// MarshalJSON serializes Status as its string name so the wire format
// is stable across any future reordering of the underlying int values.
func (s Status) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
// UnmarshalJSON accepts either the string name (preferred) or a raw int
// (for backward compatibility with older clients/snapshots).
func (s *Status) UnmarshalJSON(data []byte) error {
if len(data) > 0 && data[0] == '"' {
var name string
if err := json.Unmarshal(data, &name); err != nil {
return err
}
switch name {
case "OK":
*s = StatusOK
case "INFO":
*s = StatusInfo
case "UNKNOWN", "":
*s = StatusUnknown
case "WARN":
*s = StatusWarn
case "CRIT":
*s = StatusCrit
case "ERROR":
*s = StatusError
default:
return fmt.Errorf("unknown status %q", name)
}
return nil
}
var n int
if err := json.Unmarshal(data, &n); err != nil {
return err
}
*s = Status(n)
return nil
}
// CheckState is the result of evaluating a single rule.
type CheckState struct {
Status Status `json:"status"`