From 8798eea2a0b8b074b7a8103c7c771f541656fadf Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 14:21:44 +0000 Subject: [PATCH] docs(ax): clarify public API examples Co-Authored-By: Virgil --- api/router.go | 3 ++- config_runtime.go | 12 +++++++++--- pool/client.go | 4 ++-- server_runtime.go | 6 +++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/api/router.go b/api/router.go index ff7791a..3140336 100644 --- a/api/router.go +++ b/api/router.go @@ -74,7 +74,8 @@ type ResultsResponse struct { // RegisterRoutes mounts the monitoring endpoints on any router with HandleFunc. // -// api.RegisterRoutes(http.NewServeMux(), p) +// mux := http.NewServeMux() +// api.RegisterRoutes(mux, p) func RegisterRoutes(router Router, proxyValue *proxy.Proxy) { if router == nil || proxyValue == nil { return diff --git a/config_runtime.go b/config_runtime.go index 1295e2d..0465ea4 100644 --- a/config_runtime.go +++ b/config_runtime.go @@ -8,9 +8,12 @@ import ( "time" ) -// LoadConfig reads `config.json` and returns a validated `Config`. +// LoadConfig reads a JSON config file and validates the result. // // cfg, errorValue := proxy.LoadConfig("config.json") +// if errorValue != nil { +// return +// } func LoadConfig(path string) (*Config, error) { data, errorValue := os.ReadFile(path) if errorValue != nil { @@ -32,7 +35,10 @@ func LoadConfig(path string) (*Config, error) { // Validate checks that `bind` and `pools` are present and every enabled pool has a URL. // -// if errorValue := cfg.Validate(); errorValue != nil { return errorValue } +// cfg := &proxy.Config{Bind: []proxy.BindAddr{{Host: "127.0.0.1", Port: 3333}}, Pools: []proxy.PoolConfig{{URL: "pool-a:3333", Enabled: true}}} +// if errorValue := cfg.Validate(); errorValue != nil { +// return +// } func (c *Config) Validate() error { if c == nil { return errors.New("config is nil") @@ -53,7 +59,7 @@ func (c *Config) Validate() error { return nil } -// NewConfigWatcher watches `config.json` and calls `p.Reload(cfg)` on change. +// NewConfigWatcher watches a config file and reloads the proxy on modification. // // w := proxy.NewConfigWatcher("config.json", func(cfg *proxy.Config) { p.Reload(cfg) }) func NewConfigWatcher(path string, onChange func(*Config)) *ConfigWatcher { diff --git a/pool/client.go b/pool/client.go index 53a2e6f..f0110aa 100644 --- a/pool/client.go +++ b/pool/client.go @@ -70,7 +70,7 @@ type jsonRPCErrorBody struct { // NewStratumClient stores the pool config and listener. // -// client := pool.NewStratumClient(poolCfg, listener) +// client := pool.NewStratumClient(proxy.PoolConfig{URL: "pool.lthn.io:3333", User: "WALLET", Pass: "x"}, listener) func NewStratumClient(cfg proxy.PoolConfig, listener StratumListener) *StratumClient { return &StratumClient{ config: cfg, @@ -156,7 +156,7 @@ func (c *StratumClient) Login() { // Submit sends a share submission. Returns the sequence number for result correlation. // -// seq := client.Submit(jobID, "deadbeef", "HASH64HEX", "cn/r") +// seq := client.Submit("job-1", "deadbeef", "HASH64HEX", "cn/r") func (c *StratumClient) Submit(jobID string, nonce string, result string, algo string) int64 { sequence := atomic.AddInt64(&c.sequence, 1) params := map[string]string{ diff --git a/server_runtime.go b/server_runtime.go index f051a9d..9a0db2b 100644 --- a/server_runtime.go +++ b/server_runtime.go @@ -7,9 +7,9 @@ import ( "strconv" ) -// NewServer opens `0.0.0.0:3333` and prepares the accept loop. +// NewServer opens a listener and prepares the accept loop. // -// srv, errorValue := proxy.NewServer(bindAddress, nil, rateLimiter, onAccept) +// srv, errorValue := proxy.NewServer(proxy.BindAddr{Host: "0.0.0.0", Port: 3333}, nil, rateLimiter, onAccept) func NewServer(bindAddress BindAddr, tlsConfig *tls.Config, rateLimiter *RateLimiter, onAccept func(net.Conn, uint16)) (*Server, error) { address := net.JoinHostPort(bindAddress.Host, strconv.Itoa(int(bindAddress.Port))) listener, errorValue := net.Listen("tcp", address) @@ -65,7 +65,7 @@ func (server *Server) Start() { }() } -// Stop closes `0.0.0.0:3333` without forcing existing sockets shut. +// Stop closes the listener without forcing existing sockets shut. // // srv.Stop() func (server *Server) Stop() {