client

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 7 Imported by: 0 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the assembled peer: a persistent attach loop that dials the hub and serves an http.Handler back through the tunnel, redialing with jittered backoff. It is NewServer's counterpart for the client side — a thin veneer over the dial package's attach loop.

c := holt.NewClient("wss://hub.example.com/attach", handler,
	holt.WithBearerToken(token),
)

err := c.Run(ctx) // attaches, serves, redials; cancel ctx to stop

func New

func New(hubURL string, handler http.Handler, opts ...Option) *Client

New wires a peer that attaches to the hub's tunnel endpoint at hubURL — ws:// or wss:// (http/https are accepted as aliases) — and serves handler over the tunnel, as if it were a normal HTTP server. Nothing dials until Run.

func (*Client) Run

func (c *Client) Run(ctx context.Context) error

Run attaches to the hub and serves the handler over the tunnel, redialing with jittered exponential backoff until ctx is cancelled or the hub sends a terminal GoAway. Returns nil on a terminal GoAway (clean exit) and ctx.Err() on shutdown.

type Option

type Option interface{ ApplyClient(*Client) }

Option configures a Client; every SharedOption is one too.

func WithBearerToken

func WithBearerToken(token string) Option

WithBearerToken sends token as the Authorization bearer on the attach request — the counterpart of the server's WithAuthBearer.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient overrides the client used for the upgrade request (custom roots, proxies). Default http.DefaultClient.

func WithHeader

func WithHeader(key, value string) Option

WithHeader adds a header to the WebSocket upgrade request — whatever the edge in front of the hub wants (e.g. CF-Access-Client-Id / CF-Access-Client-Secret). Repeatable.

func WithKeepalive

func WithKeepalive(every time.Duration) Option

WithKeepalive paces WebSocket-level pings so proxies with idle timeouts keep a quiet tunnel open. Default dial.DefaultKeepalive; a negative value disables them (the inner HTTP/2 PING remains).

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger sets the logger. Default: no logging.

func WithRequestHook added in v0.36.0

func WithRequestHook(hook reqlog.Hook) Option

WithRequestHook reports every request the handler served over the tunnel, once the response is done. See reqlog.Hook.

func WithTunnelTLS

func WithTunnelTLS(cfg *tls.Config) Option

WithTunnelTLS encrypts the payload end-to-end INSIDE the tunnel: after the plaintext holt handshake the peer runs a TLS server over the stream and serves the handler over HTTPS. The hub must dial with a matching client config (hub.WithPeerTLS). Independent of any TLS on the outer WebSocket hop.

func WithVersion

func WithVersion(version string) Option

WithVersion sets the peer build version sent in Hello (observability).

Jump to

Keyboard shortcuts

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