coordclient

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package coordclient keeps an engine's registration and peer set current against a coordination service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, o Options, e *engine.Engine) error

Run registers e with the coordination service, applies the first netmap to it, and returns. It then keeps running until ctx ends: it registers again whenever the engine's registration changes and every refresh_seconds that the latest netmap announces, and it long-polls the netmap, applying each one to the engine. A netmap's hosts become the engine's peers with a lease that ends lease_seconds after the request started, and its regions, or the default region, become the engine's signaling regions.

Run fails, without starting workers, when BaseURL is not an acceptable HTTPS URL, when the engine is closed, or when the first registration or netmap fails. A 401 or 403 answer to any request expires the engine's peers at once. After a failed background netmap request the client waits before it asks again: one second, doubling with each consecutive failure up to thirty seconds, and never less than the service's Retry-After (capped at one minute). After a 429 answer it keeps the netmap version, so the next request can hold instead of returning at once. A failed registration is tried again on the next change or refresh.

Types

type Options

type Options struct {
	BaseURL   string
	TLSConfig *tls.Config
	Headers   func(context.Context) (http.Header, error)
	Logger    *slog.Logger
}

Options configures Run.

BaseURL is the HTTPS base of the coordination service. The client appends "/registration" and "/netmap" to it; a trailing slash is ignored. It must not carry user information, a query or a fragment. When a netmap lists no regions, the client gives the engine one region named BaseURL + "/signal" with ID 0.

TLSConfig verifies the service; nil selects the platform defaults.

Headers supplies every header of every request, and the client sends no other header of its own: it sends no User-Agent and asks for no compression, and the only header it adds is the Content-Length of the registration body. It is called once per request. Its error fails the request and stays wrapped, so an ErrNoCredential result can be matched with errors.Is. A nil Headers sends none.

Logger receives warnings about failed requests; nil discards them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL