mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-19 23:41:38 +02:00
refactor: clean up code and enhance utilities with new functions
This commit is contained in:
@@ -34,6 +34,8 @@ const (
|
||||
ActionContainerDie
|
||||
ActionContainerDestroy
|
||||
|
||||
ActionForceReload
|
||||
|
||||
actionContainerWakeMask = ActionContainerCreate | ActionContainerStart | ActionContainerUnpause
|
||||
actionContainerSleepMask = ActionContainerKill | ActionContainerStop | ActionContainerPause | ActionContainerDie
|
||||
)
|
||||
|
||||
@@ -14,7 +14,9 @@ type HealthCheckConfig struct {
|
||||
Timeout time.Duration `json:"timeout" validate:"omitempty,min=1s"`
|
||||
}
|
||||
|
||||
var DefaultHealthConfig = &HealthCheckConfig{
|
||||
Interval: common.HealthCheckIntervalDefault,
|
||||
Timeout: common.HealthCheckTimeoutDefault,
|
||||
func DefaultHealthConfig() *HealthCheckConfig {
|
||||
return &HealthCheckConfig{
|
||||
Interval: common.HealthCheckIntervalDefault,
|
||||
Timeout: common.HealthCheckTimeoutDefault,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package health
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Status uint8
|
||||
|
||||
const (
|
||||
@@ -13,6 +15,7 @@ const (
|
||||
NumStatuses int = iota - 1
|
||||
|
||||
HealthyMask = StatusHealthy | StatusNapping | StatusStarting
|
||||
IdlingMask = StatusNapping | StatusStarting
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
@@ -36,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
|
||||
}
|
||||
@@ -43,3 +68,7 @@ func (s Status) Good() bool {
|
||||
func (s Status) Bad() bool {
|
||||
return s&HealthyMask == 0
|
||||
}
|
||||
|
||||
func (s Status) Idling() bool {
|
||||
return s&IdlingMask != 0
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
|
||||
type (
|
||||
HealthCheckResult struct {
|
||||
Healthy bool
|
||||
Detail string
|
||||
Latency time.Duration
|
||||
Healthy bool `json:"healthy"`
|
||||
Detail string `json:"detail"`
|
||||
Latency time.Duration `json:"latency"`
|
||||
}
|
||||
WithHealthInfo interface {
|
||||
Status() Status
|
||||
|
||||
Reference in New Issue
Block a user