yonder

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 17 Imported by: ? modules, 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

yonder

Share an app on an ad-hoc URL without opening a local port. The app embeds the Go library, which opens the tunnel and returns a net.Listener. The URL dies when the listener closes or the process exits. See DESIGN.md.

Try it locally

go run ./cmd/yonder-relay -token dev

Then share something through it, for example a terminal with yterm.

Releases

Tagging vX.Y.Z on main publishes yonder-relay binaries for Linux and macOS on the GitHub release. The same tag versions the Go module and the Swift package.

Go library

go get github.com/vloothuis/yonder

Swift SDK

yonder-swift holds a Swift package (Yonder, macOS 14 and iOS 17, no dependencies) with the same model: YonderListener.listen opens the share, connections yields visitors, and YonderHTTPServer serves HTTP over them. Add it with SwiftPM:

.package(url: "https://github.com/vloothuis/yonder", from: "0.1.0")

Its tests run against a built relay:

go build -o /tmp/yonder-relay ./cmd/yonder-relay
YONDER_RELAY_BIN=/tmp/yonder-relay swift test

License

MIT

Documentation

Overview

Package yonder shares an in-process HTTP server on an ad-hoc URL through a yonder relay. The app never listens on a local port: Listen returns a net.Listener whose connections arrive over the relay tunnel.

l, err := yonder.Listen(ctx, yonder.Options{Relay: "https://share.example.com", Token: tok})
fmt.Println(l.URL())
http.Serve(l, handler)

The URL stops working as soon as the listener is closed or the process exits.

Index

Constants

This section is empty.

Variables

View Source
var ErrRelayClosed = errors.New("yonder: relay connection closed")

ErrRelayClosed is reported by Err and Accept when the relay connection ended without Close being called.

Functions

This section is empty.

Types

type Addr

type Addr string

Addr is the share's public URL without the code.

func (Addr) Network

func (Addr) Network() string

func (Addr) String

func (a Addr) String() string

type Listener

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

Listener is a net.Listener for one share. It is safe for concurrent use.

It owns one goroutine that accepts tunnel streams and one goroutine per stream while its preamble is read or an approval runs. Close stops them all and waits for them.

func Listen

func Listen(ctx context.Context, opts Options) (*Listener, error)

Listen registers a new share with the relay. ctx bounds only the handshake; the share lives until Close or until the relay connection ends.

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Accept waits for the next visitor connection.

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

Addr returns the share URL without the code.

func (*Listener) Close

func (l *Listener) Close() error

Close ends the share. The relay drops the URL immediately.

func (*Listener) Done

func (l *Listener) Done() <-chan struct{}

Done is closed when the share has ended, by Close or by losing the relay.

func (*Listener) Err

func (l *Listener) Err() error

Err returns nil while the share is live, net.ErrClosed after Close, and ErrRelayClosed if the relay connection ended first.

func (*Listener) URL

func (l *Listener) URL() string

URL returns the link to hand out. It includes the access code in the fragment, which browsers never send to servers.

type Options

type Options struct {
	// Relay is the relay's base URL, for example "https://share.example.com".
	// Plain http is accepted only for loopback and *.localhost hosts.
	Relay string
	// Token authenticates this client to the relay.
	Token string
	// Approve, if set, is called for each visitor who presented the right
	// code. It runs concurrently on a library goroutine. ctx ends when the
	// relay stops waiting. Return true to let the visitor in.
	Approve func(ctx context.Context, v Visitor) bool
	// HTTPClient is used for the handshake. Defaults to http.DefaultClient.
	HTTPClient *http.Client
}

Options configures Listen.

type Visitor

type Visitor struct {
	RemoteAddr string // as seen by the relay
	UserAgent  string // untrusted; sanitize before displaying
}

Visitor describes someone asking to open a share.

Directories

Path Synopsis
cmd
yonder-relay command
Command yonder-relay runs a yonder relay.
Command yonder-relay runs a yonder relay.
internal
relay
Package relay implements the yonder relay: it accepts tunnel connections from clients, gives each one an ad-hoc subdomain, gates visitors with the share code and proxies their HTTP traffic into the tunnel.
Package relay implements the yonder relay: it accepts tunnel connections from clients, gives each one an ad-hoc subdomain, gates visitors with the share code and proxies their HTTP traffic into the tunnel.
wire
Package wire defines the protocol shared by the yonder client and relay: handshake headers and the preamble that starts every yamux stream.
Package wire defines the protocol shared by the yonder client and relay: handshake headers and the preamble that starts every yamux stream.

Jump to

Keyboard shortcuts

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