feat(api): add events history endpoint

Expose events via REST and websocket streaming, update
swagger docs, and emit config reload/error events
This commit is contained in:
yusing
2026-02-10 18:03:30 +08:00
parent 31a7827fab
commit 3b7a6226ad
5 changed files with 194 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ import (
watcherEvents "github.com/yusing/godoxy/internal/watcher/events"
gperr "github.com/yusing/goutils/errs"
"github.com/yusing/goutils/eventqueue"
"github.com/yusing/goutils/events"
"github.com/yusing/goutils/strings/ansi"
"github.com/yusing/goutils/task"
)
@@ -38,6 +39,7 @@ func logNotifyError(action string, err error) {
Title: fmt.Sprintf("Config %s error", action),
Body: notif.ErrorBody(err),
})
events.Global.Add(events.NewEvent(events.LevelError, "config", action, err))
}
func logNotifyWarn(action string, err error) {
@@ -47,6 +49,7 @@ func logNotifyWarn(action string, err error) {
Title: fmt.Sprintf("Config %s warning", action),
Body: notif.ErrorBody(err),
})
events.Global.Add(events.NewEvent(events.LevelWarn, "config", action, err))
}
func Load() error {
@@ -90,6 +93,8 @@ func Load() error {
}
func Reload() error {
events.Global.Add(events.NewEvent(events.LevelInfo, "config", "reload", nil))
// avoid race between config change and API reload request
reloadMu.Lock()
defer reloadMu.Unlock()