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

proxy

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package proxy serves the named URLs of running jobs on one loopback port.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Forward

func Forward(params ForwardParams) error

Forward relays every connection the privileged listeners accept to the run proxy, and blocks until they all stop accepting.

func LaunchdListeners

func LaunchdListeners(string) ([]net.Listener, error)

func Probe

func Probe(params ProbeParams) int

Probe is which bind port answers behind Port, zero when what answers is not this proxy. The bind port in the reply is what separates a live redirection from one still pointing at a port the daemon no longer holds.

Types

type ForwardParams

type ForwardParams struct {
	Listeners []net.Listener
	// Target resolves where to relay. The forwarder speaks no HTTP: the Host
	// header it would need to read is the proxy's business, and a byte relay
	// keeps websockets and streaming working for free.
	Target TargetFunc
}

type Plan

type Plan struct {
	Files  []domain.ProxyPlannedFile
	Script string
}

Plan is what Apply would write and run, rendered without writing anything — the recap the user confirms is this value.

type ProbeParams

type ProbeParams struct {
	Port int
	// Timeout takes the default when zero.
	Timeout time.Duration
}

type Redirector

type Redirector interface {
	Plan() (Plan, error)
	Apply(ctx context.Context) error
	Remove(ctx context.Context) error
	Inspect() domain.ProxyStatus
}

func NewRedirector

func NewRedirector(_ RedirectorParams) Redirector

type RedirectorParams

type RedirectorParams struct {
	// Root is what every path is joined onto, "/" in production. It exists so
	// the tests never touch a system file.
	Root string
}

type Registry

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

Registry is the routing table. It is a projection of the jobs the daemon is running, so it is only ever written from where those start and stop.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Add

func (r *Registry) Add(route domain.ProxyRoute)

func (*Registry) List

func (r *Registry) List() []domain.ProxyRoute

func (*Registry) Lookup

func (r *Registry) Lookup(host string) (domain.ProxyRoute, bool)

func (*Registry) Remove

func (r *Registry) Remove(host string)

type Server

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

func NewServer

func NewServer(params ServerParams) *Server

func (*Server) Close

func (s *Server) Close() error

func (*Server) Port

func (s *Server) Port() int

Port is the port the listener actually took, zero before Start.

func (*Server) Start

func (s *Server) Start() error

Start binds the first usable port from the one asked for and serves until Close. Usable means free *and* one a browser will open: a port on the browsers' blocked list serves nothing however well it binds, so it is stepped over exactly like an occupied one. The port is not stable across restarts when the preferred one is taken, and that is the trade this makes: a caller reaches a job by name, so the number is a transport detail `run url` resolves for them — where a job's own port is one they memorise, which is why those never move.

type ServerParams

type ServerParams struct {
	Port int
	// Span is how many ports from Port are tried. Zero takes the default.
	Span     int
	Registry *Registry
}

type TargetFunc

type TargetFunc func() (int, error)

TargetFunc names the port the run proxy is really on. It is a function and not a number because the daemon may fall back to another port, or restart on one: baking a port into the LaunchAgent would make every such move break the privileged port until the agent was reinstalled.

func Cached

func Cached(resolve TargetFunc, ttl time.Duration) TargetFunc

Cached spares the daemon a round-trip per connection without letting the forwarder keep aiming at a port the daemon has left.

Jump to

Keyboard shortcuts

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