tunnel

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cloudflared

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

Cloudflared runs cloudflared as a managed subprocess bound to ephemerd's lifetime. On Linux the child gets SIGTERM the moment the parent thread exits (Pdeathsig) — cloudflared cannot outlive ephemerd, even under SIGKILL or panic. On other platforms the guarantee is best-effort via Close().

func NewCloudflared

func NewCloudflared(opts CloudflaredOptions) (*Cloudflared, error)

NewCloudflared validates options and returns a provider. It does not download the binary or start the subprocess — that happens in Listen.

func (*Cloudflared) Listen

func (c *Cloudflared) Listen(ctx context.Context) (net.Listener, error)

Listen starts the local webhook listener, ensures the cloudflared binary is present, writes config + credentials, and spawns cloudflared bound to this process's lifetime. The returned listener is what ephemerd Accepts on; closing it also stops cloudflared.

func (*Cloudflared) PublicURL

func (c *Cloudflared) PublicURL() string

PublicURL returns the https URL cloudflared exposes to the internet.

type CloudflaredOptions

type CloudflaredOptions struct {
	Token    string // cloudflared tunnel token (base64-encoded JSON with account_tag, tunnel_id, secret)
	Hostname string // public FQDN of the tunnel (for PublicURL)
	Version  string // cloudflared version to download if binary missing; if empty, uses defaultCloudflaredVersion
	DataDir  string // ephemerd data dir; provider carves out <DataDir>/cloudflared/ for binary + config
	Port     int    // local port cloudflared forwards to (matches ephemerd's webhook listener)
}

CloudflaredOptions configures the Cloudflared provider.

type LocalTunnel

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

LocalTunnel implements Provider using localtunnel.

func NewLocalTunnel

func NewLocalTunnel(baseURL string) *LocalTunnel

NewLocalTunnel creates a localtunnel provider. baseURL is optional — if empty, uses the public localtunnel service (loca.lt). Set baseURL to use a self-hosted localtunnel server.

func (*LocalTunnel) Listen

func (lt *LocalTunnel) Listen(ctx context.Context) (net.Listener, error)

Listen establishes a tunnel, retrying on failure. Each attempt gets a 10s timeout. Retries continue for up to 2 minutes or until ctx is cancelled. This is blocking — if localtunnel is configured, ephemerd cannot receive webhooks without a tunnel.

func (*LocalTunnel) PublicURL

func (lt *LocalTunnel) PublicURL() string

type Ngrok

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

Ngrok implements Provider using ngrok-go.

func NewNgrok

func NewNgrok(authtoken string) (*Ngrok, error)

NewNgrok creates an ngrok tunnel provider. The auth token is resolved in order: explicit token, NGROK_AUTHTOKEN env var.

func (*Ngrok) Listen

func (n *Ngrok) Listen(ctx context.Context) (net.Listener, error)

func (*Ngrok) PublicURL

func (n *Ngrok) PublicURL() string

type Options

type Options struct {
	Provider string // "ngrok" | "localtunnel" | "cloudflared"

	// ngrok
	NgrokAuthtoken string

	// localtunnel
	LocalTunnelBaseURL string

	// cloudflared
	CloudflaredToken    string
	CloudflaredHostname string
	CloudflaredVersion  string
	CloudflaredDataDir  string // <ephemerd data dir> — provider carves out cloudflared/ under this
	CloudflaredPort     int    // local webhook port cloudflared forwards to
}

Options are the union of settings any provider might need. Fields unused by the chosen provider are ignored — this keeps the constructor signature stable as new providers land.

type Provider

type Provider interface {
	// Listen creates a tunnel and returns a net.Listener with a public URL.
	// The tunnel is torn down when the listener is closed or ctx is cancelled.
	Listen(ctx context.Context) (net.Listener, error)

	// PublicURL returns the public URL of the tunnel after Listen succeeds.
	PublicURL() string
}

Provider creates a publicly-reachable listener for receiving webhooks. Implementations manage the tunnel lifecycle: Listen creates the tunnel, and closing the returned listener (or cancelling the context) tears it down.

func New

func New(o Options) (Provider, error)

New creates a tunnel provider from the options.

Jump to

Keyboard shortcuts

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