simplify some code and implement metrics storage

This commit is contained in:
yusing
2025-02-17 07:18:59 +08:00
parent 1b7b6196c5
commit a8a209f0b0
11 changed files with 204 additions and 70 deletions

View File

@@ -1,5 +1,7 @@
package health
import "encoding/json"
type Status uint8
const (
@@ -37,6 +39,28 @@ func (s Status) MarshalJSON() ([]byte, error) {
return []byte(`"` + s.String() + `"`), nil
}
func (s *Status) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
switch str {
case "healthy":
*s = StatusHealthy
case "unhealthy":
*s = StatusUnhealthy
case "napping":
*s = StatusNapping
case "starting":
*s = StatusStarting
case "error":
*s = StatusError
default:
*s = StatusUnknown
}
return nil
}
func (s Status) Good() bool {
return s&HealthyMask != 0
}