client

package
v0.24.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package client implements the expose tunnel client that registers with the server, maintains a WebSocket session, and proxies traffic to a local port.

Index

Constants

This section is empty.

Variables

View Source
var ErrAutoUpdated = errors.New("binary updated; restart required")

ErrAutoUpdated is returned from Client.Run when the binary was replaced by the auto-updater and the caller should restart the process.

Functions

func ResolveMachineID added in v0.14.0

func ResolveMachineID(hostname string) string

ResolveMachineID returns a stable machine identifier for client-side naming and registration metadata, falling back to the provided hostname.

Types

type Client

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

Client connects to the expose server and proxies public traffic to a local port.

func New

func New(cfg config.ClientConfig, logger *slog.Logger) *Client

New creates a Client with the given configuration and logger.

func (*Client) Run

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

func (*Client) SetAutoUpdate added in v0.6.0

func (c *Client) SetAutoUpdate(enabled bool)

SetAutoUpdate enables background self-update. When enabled the client periodically checks for new releases and also reacts to server version changes detected during reconnection. If an update is applied the Run method returns ErrAutoUpdated.

func (*Client) SetDisplay added in v0.5.0

func (c *Client) SetDisplay(d *Display)

SetDisplay configures the interactive terminal display. When set, the client renders an ngrok-style interface instead of plain structured log output for tunnel status and request logging.

func (*Client) SetLifecycleHooks added in v0.16.0

func (c *Client) SetLifecycleHooks(hooks LifecycleHooks)

SetLifecycleHooks configures optional callbacks for tunnel lifecycle events.

func (*Client) SetLogger added in v0.5.0

func (c *Client) SetLogger(l *slog.Logger)

SetLogger replaces the client's logger.

func (*Client) SetTrafficSink added in v0.21.0

func (c *Client) SetTrafficSink(sink TrafficRecorder)

func (*Client) SetVersion added in v0.5.0

func (c *Client) SetVersion(v string)

SetVersion sets the client version string for server exchange.

type Display added in v0.5.0

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

Display renders an ngrok-inspired terminal interface for the tunnel client. It redraws the entire screen on every state change so the header, counters, and request log are always visible. Safe for concurrent use.

func NewDisplay added in v0.5.0

func NewDisplay(color bool) *Display

NewDisplay creates a Display that writes to stdout. When color is true, ANSI escape codes are used for styling.

func (*Display) Cleanup added in v0.5.0

func (d *Display) Cleanup()

Cleanup restores the terminal cursor. Call on shutdown.

func (*Display) LogRequest added in v0.5.0

func (d *Display) LogRequest(method, path string, status int, duration time.Duration, headers map[string][]string)

LogRequest records an HTTP request and redraws. headers is used to extract the client IP (X-Forwarded-For) for tracking unique visitors. Pass nil if headers are not available.

func (*Display) RecordTraffic added in v0.21.0

func (d *Display) RecordTraffic(direction traffic.Direction, bytes int64)

func (*Display) SetLocalHealthTarget added in v0.22.0

func (d *Display) SetLocalHealthTarget(localAddr string)

func (*Display) ShowBanner added in v0.5.0

func (d *Display) ShowBanner(version string)

ShowBanner sets the version string and draws the initial screen.

func (*Display) ShowInfo added in v0.5.0

func (d *Display) ShowInfo(msg string)

ShowInfo sets the most recent info notice and redraws.

func (*Display) ShowLatency added in v0.7.0

func (d *Display) ShowLatency(rtt time.Duration)

ShowLatency updates the displayed round-trip latency and redraws.

func (*Display) ShowReconnecting added in v0.5.0

func (d *Display) ShowReconnecting(reason string)

ShowReconnecting sets the status to reconnecting and redraws.

func (*Display) ShowTunnelInfo added in v0.5.0

func (d *Display) ShowTunnelInfo(publicURL, localAddr, tlsMode, tunnelID string, protected bool, transport string)

ShowTunnelInfo updates the tunnel connection details and redraws.

func (*Display) ShowUpdateStatus added in v0.5.0

func (d *Display) ShowUpdateStatus(latestVersion string)

ShowUpdateStatus sets the available update version and redraws. Pass an empty string to indicate the client is up to date.

func (*Display) ShowVersions added in v0.5.0

func (d *Display) ShowVersions(clientVersion, serverVersion string, wafEnabled bool)

ShowVersions sets the client and server version strings and redraws.

func (*Display) ShowWAFStats added in v0.9.0

func (d *Display) ShowWAFStats(blocked int64)

ShowWAFStats updates the displayed WAF-blocked request count and redraws.

func (*Display) ShowWarning added in v0.5.0

func (d *Display) ShowWarning(msg string)

ShowWarning sets the most recent warning notice and redraws.

func (*Display) ToggleSessionDetails added in v0.21.0

func (d *Display) ToggleSessionDetails()

ToggleSessionDetails shows or hides the extra session detail row.

func (*Display) TrackWSClose added in v0.5.0

func (d *Display) TrackWSClose(id string)

TrackWSClose removes a WebSocket stream and redraws. A debounced display floor prevents the counter from briefly dipping during a page refresh (close + immediate reopen).

func (*Display) TrackWSOpen added in v0.5.0

func (d *Display) TrackWSOpen(id, path string, headers map[string][]string)

TrackWSOpen registers a new WebSocket stream and redraws. headers is used to extract the client IP for tracking unique visitors.

type LifecycleHooks added in v0.16.0

type LifecycleHooks struct {
	OnTunnelReady     func(TunnelReadyEvent)
	OnRegisterFailure func(RegisterFailureEvent)
	OnSessionDrop     func(SessionDisconnectEvent)
}

LifecycleHooks allows callers to observe client lifecycle transitions without scraping log output.

type RegisterFailureEvent added in v0.16.0

type RegisterFailureEvent struct {
	Err       error
	RetryIn   time.Duration
	WillRetry bool
}

RegisterFailureEvent is emitted when tunnel registration fails.

type SessionDisconnectEvent added in v0.16.0

type SessionDisconnectEvent struct {
	Err error
}

SessionDisconnectEvent is emitted when an active tunnel session drops and the client will attempt to reconnect.

type TrafficRecorder added in v0.21.0

type TrafficRecorder interface {
	RecordTraffic(direction traffic.Direction, bytes int64)
}

type TrafficSinkFunc added in v0.21.0

type TrafficSinkFunc func(direction traffic.Direction, bytes int64)

func (TrafficSinkFunc) RecordTraffic added in v0.21.0

func (f TrafficSinkFunc) RecordTraffic(direction traffic.Direction, bytes int64)

type TunnelReadyEvent added in v0.16.0

type TunnelReadyEvent struct {
	TunnelID      string
	PublicURL     string
	Transport     string
	ServerVersion string
	ServerTLSMode string
	WAFEnabled    bool
}

TunnelReadyEvent is emitted when a client successfully registers and has an active tunnel session ready.

Directories

Path Synopsis
Package settings persists and loads client credentials (server URL and API key) in a JSON file under the user's home directory.
Package settings persists and loads client credentials (server URL and API key) in a JSON file under the user's home directory.

Jump to

Keyboard shortcuts

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