mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 00:38:33 +02:00
simplify some code and implement metrics storage
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user