package check import ( "encoding/json" "time" ) //Result denotes the status from a status check. type Result uint8 const ( //Online means all requests were fulfilled by the remote end. Online Result = iota //Unstable means some requests were fulfilled by the remote end. Unstable //Offline means every requests to the remote end has failed. Offline ) //TryCount is the amount of times requests will be made to the remote end. const TryCount = 3 func statusFromSuccessCount(count int) Result { if count == 0 { return Offline } if count < TryCount { return Unstable } return Online } func divide(t time.Duration, dividend int) time.Duration { return time.Duration(int(t) / dividend) } func (r Result) String() string { switch r { case Online: return "online" case Unstable: return "unstable" case Offline: return "offline" } panic("Unexpected value") } func (r Result) MarshalJSON() ([]byte, error) { return json.Marshal(r.String()) }