From f6a8187f4ec995a2a1a9c0f0a522d0114de0c60a Mon Sep 17 00:00:00 2001 From: Luther Wen Xu Date: Thu, 23 Apr 2020 15:41:02 +0800 Subject: [PATCH] check: Add JSON marshalling --- check/check.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/check/check.go b/check/check.go index f1482ba..1a66819 100644 --- a/check/check.go +++ b/check/check.go @@ -1,6 +1,7 @@ package check import ( + "encoding/json" "time" ) @@ -32,3 +33,19 @@ func statusFromSuccessCount(count int) Result { 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()) +}