From 05b0bb5ea414ef6774f8d7e242614de50702c39c Mon Sep 17 00:00:00 2001 From: Virgil Date: Sun, 5 Apr 2026 01:15:03 +0000 Subject: [PATCH] docs(ax): improve public route and log examples Co-Authored-By: Virgil --- api/router.go | 10 +++++++--- log/impl.go | 8 ++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/router.go b/api/router.go index f4023ad..7434e71 100644 --- a/api/router.go +++ b/api/router.go @@ -11,13 +11,17 @@ import ( "dappco.re/go/proxy" ) -type Router interface { +// RouteRegistrar accepts HTTP handler registrations. +// +// mux := http.NewServeMux() +// api.RegisterRoutes(mux, p) +type RouteRegistrar interface { HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) } // mux := http.NewServeMux() // api.RegisterRoutes(mux, p) // GET /1/summary, /1/workers, /1/miners -func RegisterRoutes(router Router, p *proxy.Proxy) { +func RegisterRoutes(router RouteRegistrar, p *proxy.Proxy) { if router == nil || p == nil { return } @@ -26,7 +30,7 @@ func RegisterRoutes(router Router, p *proxy.Proxy) { registerJSONGetRoute(router, p, "/1/miners", func() any { return p.MinersDocument() }) } -func registerJSONGetRoute(router Router, authoriser *proxy.Proxy, pattern string, renderDocument func() any) { +func registerJSONGetRoute(router RouteRegistrar, authoriser *proxy.Proxy, pattern string, renderDocument func() any) { router.HandleFunc(pattern, func(w http.ResponseWriter, request *http.Request) { if status, ok := allowMonitoringRequest(authoriser, request); !ok { switch status { diff --git a/log/impl.go b/log/impl.go index 085727e..e36fcca 100644 --- a/log/impl.go +++ b/log/impl.go @@ -33,7 +33,7 @@ func (l *AccessLog) Close() { } } -// OnLogin writes a CONNECT line. +// OnLogin writes `2026-04-04T12:00:00Z CONNECT 10.0.0.1 WALLET XMRig/6.21.0`. func (l *AccessLog) OnLogin(e proxy.Event) { if l == nil || e.Miner == nil { return @@ -41,7 +41,7 @@ func (l *AccessLog) OnLogin(e proxy.Event) { l.writeConnectLine(e.Miner.IP(), e.Miner.User(), e.Miner.Agent()) } -// OnClose writes a CLOSE line with byte counts. +// OnClose writes `2026-04-04T12:00:00Z CLOSE 10.0.0.1 WALLET rx=512 tx=4096`. func (l *AccessLog) OnClose(e proxy.Event) { if l == nil || e.Miner == nil { return @@ -73,7 +73,7 @@ func (l *ShareLog) Close() { } } -// OnAccept writes an ACCEPT line. +// OnAccept writes `2026-04-04T12:00:00Z ACCEPT WALLET diff=100000 latency=82ms`. func (l *ShareLog) OnAccept(e proxy.Event) { if l == nil || e.Miner == nil { return @@ -81,7 +81,7 @@ func (l *ShareLog) OnAccept(e proxy.Event) { l.writeAcceptLine(e.Miner.User(), e.Diff, uint64(e.Latency)) } -// OnReject writes a REJECT line. +// OnReject writes `2026-04-04T12:00:00Z REJECT WALLET reason="Invalid nonce"`. func (l *ShareLog) OnReject(e proxy.Event) { if l == nil || e.Miner == nil { return