mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-28 03:51:08 +01:00
fix: json marshaling
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -21,7 +22,7 @@ type JSONRepresentation struct {
|
||||
Extra map[string]any
|
||||
}
|
||||
|
||||
func (jsonRepr *JSONRepresentation) MarshalMap() map[string]any {
|
||||
func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) {
|
||||
var url string
|
||||
if jsonRepr.URL != nil {
|
||||
url = jsonRepr.URL.String()
|
||||
@@ -29,7 +30,7 @@ func (jsonRepr *JSONRepresentation) MarshalMap() map[string]any {
|
||||
if url == "http://:0" {
|
||||
url = ""
|
||||
}
|
||||
return map[string]any{
|
||||
return json.Marshal(map[string]any{
|
||||
"name": jsonRepr.Name,
|
||||
"config": jsonRepr.Config,
|
||||
"started": jsonRepr.Started.Unix(),
|
||||
@@ -44,5 +45,5 @@ func (jsonRepr *JSONRepresentation) MarshalMap() map[string]any {
|
||||
"detail": jsonRepr.Detail,
|
||||
"url": url,
|
||||
"extra": jsonRepr.Extra,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -179,8 +179,8 @@ func (mon *monitor) String() string {
|
||||
return mon.Name()
|
||||
}
|
||||
|
||||
// MarshalMap implements health.HealthMonitor.
|
||||
func (mon *monitor) MarshalMap() map[string]any {
|
||||
// MarshalJSON implements health.HealthMonitor.
|
||||
func (mon *monitor) MarshalJSON() ([]byte, error) {
|
||||
res := mon.lastResult.Load()
|
||||
if res == nil {
|
||||
res = &health.HealthCheckResult{
|
||||
@@ -198,7 +198,7 @@ func (mon *monitor) MarshalMap() map[string]any {
|
||||
LastSeen: GetLastSeen(mon.service),
|
||||
Detail: res.Detail,
|
||||
URL: mon.url.Load(),
|
||||
}).MarshalMap()
|
||||
}).MarshalJSON()
|
||||
}
|
||||
|
||||
func (mon *monitor) checkUpdateHealth() error {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -25,6 +26,7 @@ type (
|
||||
fmt.Stringer
|
||||
WithHealthInfo
|
||||
Name() string
|
||||
json.Marshaler
|
||||
}
|
||||
HealthChecker interface {
|
||||
CheckHealth() (result *HealthCheckResult, err error)
|
||||
|
||||
Reference in New Issue
Block a user