check: Add JSON marshalling

master
Luther Wen Xu 2020-04-23 15:41:02 +07:00
parent 3e40b6ecdb
commit f6a8187f4e
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
1 changed files with 17 additions and 0 deletions

@ -1,6 +1,7 @@
package check package check
import ( import (
"encoding/json"
"time" "time"
) )
@ -32,3 +33,19 @@ func statusFromSuccessCount(count int) Result {
func divide(t time.Duration, dividend int) time.Duration { func divide(t time.Duration, dividend int) time.Duration {
return time.Duration(int(t) / dividend) 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())
}