etunnel

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 13 Imported by: 1 module, 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.

README

etunnel SDK for Go (canonical)

The reference SDK: full streaming bodies and WebSocket (101 upgrade) pass-through — everything the buffer-based ports in ../sdks/ build down to.

import "github.com/topcheer/etunnel/sdk"

t, err := sdk.Connect("wss://t.etun.uk/tunnel", "127.0.0.1:3000",
    sdk.Options{Token: os.Getenv("ETUNNEL_TOKEN")})
// t.URL() -> https://<subdomain>.t.etun.uk
defer t.Close()
  • Zero dependencies outside the Go standard library.
  • Manifest: the module's root go.mod (module etunnel) — installed via go get github.com/topcheer/etunnel@v1.0.2 once the repo is tagged, served by proxy.golang.org.
  • Distributed through the Go module proxy (git tags); no package upload step.
  • Race-detector-enabled integration tests live at the repo root (integration_test.go).

See ../PROTOCOL.md for the wire protocol and ../sdks/README.md for the other 19 languages.

Documentation

Overview

Package etunnel is the Go SDK for etunnel tunnels: expose a local service on the public internet with one call.

t, err := etunnel.Connect(ctx, etunnel.Options{Server: "wss://t.example.com/tunnel", LocalAddr: ":8080"})
fmt.Println(t.URL()) // https://quick-fox-42.t.example.com

Index

Constants

This section is empty.

Variables

View Source
var DefaultServer = "wss://t.etun.uk/tunnel"

DefaultServer is the connect target when Options.Server is empty; overridable at link time: -ldflags "-X etunnel/sdk.DefaultServer=wss://t.example.com/tunnel"

Functions

func NormalizeServerURL

func NormalizeServerURL(s string) string

NormalizeServerURL canonicalizes a server address into a ws(s) URL.

Types

type APIError

type APIError struct {
	Code    string
	Message string
}

APIError is a policy error returned by the server during handshake.

func (*APIError) Error

func (e *APIError) Error() string

type Options

type Options struct {
	// Server is the tunnel server endpoint, e.g. "wss://t.example.com/tunnel".
	// A bare host gets "wss://" and "/tunnel" defaults.
	Server string
	// LocalAddr is the local service address to expose ("127.0.0.1:8080").
	LocalAddr string
	// Subdomain requests a custom subdomain (requires a paid plan token).
	Subdomain string
	// Token is a paid plan API key.
	Token string
	// Client is a free-form client identification string.
	Client string
	// OnLog, when set, receives lifecycle log lines.
	OnLog func(format string, args ...any)
}

Options configures a tunnel.

type Tunnel

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

Tunnel is one live reverse tunnel.

func Connect

func Connect(ctx context.Context, opts Options) (*Tunnel, error)

Connect establishes a reverse tunnel and returns it once the server has assigned a public hostname.

func (*Tunnel) Close

func (t *Tunnel) Close(reason string)

Close shuts the tunnel down.

func (*Tunnel) CloseReason

func (t *Tunnel) CloseReason() string

CloseReason returns why the tunnel ended ("" while running).

func (*Tunnel) Done

func (t *Tunnel) Done() <-chan struct{}

Done is closed when the tunnel ends (server closed it, TTL expired, connection lost or Close was called).

func (*Tunnel) ExpiresAt

func (t *Tunnel) ExpiresAt() time.Time

ExpiresAt returns the tunnel expiry reported by the server (zero = none).

func (*Tunnel) Hostname

func (t *Tunnel) Hostname() string

Hostname returns the public hostname.

func (*Tunnel) Plan

func (t *Tunnel) Plan() string

Plan returns the plan name reported by the server.

func (*Tunnel) Subdomain

func (t *Tunnel) Subdomain() string

Subdomain returns the assigned subdomain label.

func (*Tunnel) URL

func (t *Tunnel) URL() string

URL returns the public URL of the tunnel.

Jump to

Keyboard shortcuts

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