fix: json marshaling

This commit is contained in:
yusing
2025-04-26 01:31:22 +08:00
parent db6fc65876
commit 03d609e4e1
8 changed files with 28 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
package idlewatcher
import (
"encoding/json"
"iter"
"strconv"
@@ -11,9 +12,9 @@ type watcherDebug struct {
*Watcher
}
func (w watcherDebug) MarshalMap() map[string]any {
func (w watcherDebug) MarshalJSON() ([]byte, error) {
state := w.state.Load()
return map[string]any{
return json.Marshal(map[string]any{
"name": w.Name(),
"state": map[string]string{
"status": string(state.status),
@@ -23,7 +24,7 @@ func (w watcherDebug) MarshalMap() map[string]any {
"expires": strutils.FormatTime(w.expires()),
"last_reset": strutils.FormatTime(w.lastReset.Load()),
"config": w.cfg,
}
})
}
func Watchers() iter.Seq2[string, watcherDebug] {