Help us shape the future of Go! Take the 2026 Go Developer Survey

tunnel

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package tunnel publishes a local HTTP listener on a public https URL through a third-party connector, so devices that cannot route to the host (a phone on cellular, a laptop on another network) can still enroll and join the mesh. Providers wrap external programs, or name a forwarder the hosting platform already runs; the mesh only learns the resulting URL, which it advertises exactly like a configured external URL.

Index

Constants

View Source
const CloudflaredLicenseURL = "https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/license/"

CloudflaredLicenseURL is what a user accepts by installing cloudflared.

View Source
const CloudflaredVersion = "2026.9.1"

CloudflaredVersion is the cloudflared release this build knows how to install. Bump it together with cloudflaredAssets: the digests are the only thing standing between "download from GitHub" and "run whatever answered".

View Source
const DefaultCloudflaredReleaseURL = "https://github.com/cloudflare/cloudflared/releases/download/"

DefaultCloudflaredReleaseURL is the GitHub releases download prefix.

Variables

View Source
var ErrCloudflaredUnavailable = errors.New("cloudflared not found")

ErrCloudflaredUnavailable is returned when no usable cloudflared exists and the provider was not allowed to install one.

Functions

func Names

func Names() []string

Names lists the registered providers.

Types

type Cloudflare

type Cloudflare struct {
	// Binary is an explicit cloudflared executable; when set, nothing else
	// is tried.
	Binary string
	// Timeout bounds how long Open waits for the URL and then for its
	// hostname to be published in DNS; defaults to 30s.
	Timeout time.Duration
	// InstallDir is where a downloaded cloudflared is kept (agentmesh-one uses
	// <data-dir>/bin). Empty disables both the cache and downloads.
	InstallDir string
	// Consent is asked before downloading; installing cloudflared means
	// accepting Cloudflare's license, so this must be an explicit choice.
	// Nil never downloads.
	Consent func(version, url string) bool
	// ReleaseURL overrides the GitHub release download prefix (mirrors,
	// tests). The pinned digests still apply.
	ReleaseURL string
	// HTTPClient performs the download; nil uses a 10 minute timeout.
	HTTPClient *http.Client
	// LookupHost asks whether the assigned hostname exists yet; nil asks
	// the zone's authoritative nameserver (see authoritativeLookup). Tests
	// stub it.
	LookupHost func(ctx context.Context, host string) ([]string, error)
	// Token is an optional named tunnel token (from --tunnel-token-path
	// or AGENTMESH_TUNNEL_TOKEN). When set, Open runs
	// `cloudflared tunnel --no-autoupdate run --url <target>` with
	// TUNNEL_TOKEN in the child environment instead of a random
	// trycloudflare.com quick tunnel, and publishes ExternalURL.
	Token string
	// ExternalURL is the public https:// hostname routed to the named
	// tunnel when Token is set.
	ExternalURL string
}

Cloudflare opens a TryCloudflare quick tunnel: `cloudflared tunnel --url <target>` publishes the target on a random https://*.trycloudflare.com subdomain with no account or login. Quick tunnels are a development convenience with no SLA; cloudflared prints the assigned URL on its log output, which is the only thing this provider parses.

The connector binary is resolved in order: Binary if set, `cloudflared` on PATH, a previously installed copy under InstallDir whose digest still matches the pin, and finally a fresh download of the pinned release, which happens only if Consent agrees. A cached copy that fails verification is never run.

func (*Cloudflare) Name

func (c *Cloudflare) Name() string

Name implements Provider.

func (*Cloudflare) Open

func (c *Cloudflare) Open(ctx context.Context, target string) (Tunnel, error)

Open implements Provider.

type Codespaces

type Codespaces struct {
	// Getenv reads the platform variables; nil uses os.Getenv.
	Getenv func(string) string
	// Transport performs the probe requests; nil uses the default.
	Transport http.RoundTripper
	// ProbeTimeout bounds how long the probe waits for a first answer;
	// defaults to 90s.
	ProbeTimeout time.Duration
	// ProbeInterval is the pause between probe requests; defaults to 2s.
	ProbeInterval time.Duration
}

Codespaces publishes the target on the https URL GitHub Codespaces assigns to a forwarded port, https://<CODESPACE_NAME>-<port>.<forwarding domain>. GitHub runs the forwarder, so nothing is started here and the URL is known at once. A forwarded port is private to the codespace owner until they make it public, and no API inside the codespace can do that; Open returns immediately and a background probe reports whether the URL answers from the internet, and what to click if it does not.

func (*Codespaces) Name

func (c *Codespaces) Name() string

Name implements Provider.

func (*Codespaces) Open

func (c *Codespaces) Open(ctx context.Context, target string) (Tunnel, error)

Open implements Provider.

type Provider

type Provider interface {
	// Name is the operator-facing identifier (e.g. "cloudflare").
	Name() string
	// Open publishes target, a local http://host:port URL, and returns once
	// the public URL is known or ctx expires.
	Open(ctx context.Context, target string) (Tunnel, error)
}

Provider opens tunnels through one connector implementation.

func Lookup

func Lookup(name string) (Provider, error)

Lookup returns a fresh provider by name.

type Tunnel

type Tunnel interface {
	// URL is the public https base URL that reaches the local target.
	URL() string
	// Done is closed once the tunnel has stopped forwarding, for whatever
	// reason; Err then reports why (nil after Close).
	Done() <-chan struct{}
	Err() error
	// Close tears the tunnel down.
	Close() error
}

Tunnel is an open public endpoint forwarding to a local target.

Jump to

Keyboard shortcuts

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