tunnel

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tunnel manages a Cloudflare "quick tunnel" (cloudflared) as a child process, exposing the local control plane at a public https://*.trycloudflare.com URL with no account or public IP required. It parses the assigned URL from cloudflared's stderr and surfaces start/stop/status so the UI can drive it.

cloudflared is an EXTERNAL binary (not a Go dependency): the manager detects it on PATH and never downloads it — a supply-chain-hygiene choice matching how the project treats adb/idevice tooling. When it is absent, Status.Installed is false and the UI shows install guidance.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("tunnel manager is closed")

ErrClosed is returned when Start is called after Manager.Close.

Functions

This section is empty.

Types

type Manager

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

Manager owns at most one cloudflared process at a time.

func New

func New(controlPort func() string) *Manager

New builds a Manager. controlPort returns the loopback port string (e.g. "9966") the tunnel should forward to.

func (*Manager) Close added in v1.6.0

func (m *Manager) Close()

Close stops the child process, waits for every child to be reaped, then stops the callback dispatcher. It is safe to call repeatedly.

func (*Manager) Installed

func (m *Manager) Installed() bool

Installed reports whether cloudflared is available on PATH.

func (*Manager) SetOnURL

func (m *Manager) SetOnURL(fn func(string))

SetOnURL registers a callback fired when the public URL becomes known, and again with "" when the tunnel stops. Used to broadcast a live UI update.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) (Status, error)

Start launches cloudflared if not already running. It is idempotent — a second call while running just returns the current status. The public URL is filled in asynchronously as cloudflared reports it. The caller is responsible for ensuring authentication is configured before exposing the surface (see the control layer, which refuses to start a tunnel with no API keys).

func (*Manager) Status

func (m *Manager) Status() Status

Status returns a snapshot.

func (*Manager) Stop

func (m *Manager) Stop() error

Stop terminates the tunnel process. It is a no-op when not running.

type Status

type Status struct {
	Installed bool   `json:"installed"` // cloudflared is on PATH
	Running   bool   `json:"running"`   // a tunnel process is live
	URL       string `json:"url"`       // public URL (fills in shortly after start)
	Err       string `json:"err"`       // last error (start failure / crash)
	StartedAt int64  `json:"startedAt"` // unix millis
}

Status is a snapshot of the tunnel manager's state.

Jump to

Keyboard shortcuts

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