tunnel

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package tunnel provides management for tunnel services like Cloudflare and ngrok.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Provider   Provider
	LocalPort  int
	LocalHost  string // defaults to "localhost"
	BinaryPath string // optional: path to tunnel binary, otherwise uses PATH
}

Config holds tunnel configuration.

type Manager

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

Manager manages tunnel instances.

func NewManager

func NewManager() *Manager

NewManager creates a new tunnel manager.

func (*Manager) ActiveCount

func (m *Manager) ActiveCount() int

ActiveCount returns the number of active tunnels.

func (*Manager) Get

func (m *Manager) Get(id string) (*Tunnel, bool)

Get returns a tunnel by ID.

func (*Manager) List

func (m *Manager) List() []TunnelInfo

List returns information about all tunnels.

func (*Manager) Shutdown

func (m *Manager) Shutdown(ctx context.Context) error

Shutdown stops all tunnels.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, id string, config Config) (*Tunnel, error)

Start starts a tunnel for the given proxy.

func (*Manager) Stop

func (m *Manager) Stop(ctx context.Context, id string) error

Stop stops a tunnel by ID.

type Provider

type Provider string

Provider represents a tunnel service provider.

const (
	// ProviderCloudflare uses cloudflared for Cloudflare Quick Tunnels.
	ProviderCloudflare Provider = "cloudflare"
	// ProviderNgrok uses ngrok for tunneling.
	ProviderNgrok Provider = "ngrok"
)

type State

type State uint32

State represents the tunnel state.

const (
	StateIdle State = iota
	StateStarting
	StateConnected
	StateFailed
	StateStopped
)

func (State) String

func (s State) String() string

type Tunnel

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

Tunnel represents a running tunnel instance.

func New

func New(config Config) *Tunnel

New creates a new tunnel with the given configuration.

func (*Tunnel) Done

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

Done returns a channel that's closed when the tunnel exits.

func (*Tunnel) Info

func (t *Tunnel) Info() TunnelInfo

Info returns information about the tunnel.

func (*Tunnel) OnURL

func (t *Tunnel) OnURL(fn func(url string))

OnURL sets a callback that's invoked when the public URL is discovered.

func (*Tunnel) PublicURL

func (t *Tunnel) PublicURL() string

PublicURL returns the public URL if available.

func (*Tunnel) Start

func (t *Tunnel) Start(ctx context.Context) error

Start starts the tunnel and returns immediately. Use WaitForURL to wait for the public URL to be available.

func (*Tunnel) State

func (t *Tunnel) State() State

State returns the current tunnel state.

func (*Tunnel) Stop

func (t *Tunnel) Stop(ctx context.Context) error

Stop stops the tunnel.

func (*Tunnel) WaitForURL

func (t *Tunnel) WaitForURL(ctx context.Context) (string, error)

WaitForURL waits for the public URL to be available or timeout.

type TunnelInfo

type TunnelInfo struct {
	Provider  Provider `json:"provider"`
	State     string   `json:"state"`
	PublicURL string   `json:"public_url,omitempty"`
	LocalAddr string   `json:"local_addr"`
	Error     string   `json:"error,omitempty"`
}

TunnelInfo contains information about a tunnel.

Jump to

Keyboard shortcuts

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