docs(ax): clarify public API examples
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
f2fd83caad
commit
8798eea2a0
4 changed files with 16 additions and 9 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue