routing

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package routing provides hostname-based reverse proxy routing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveProxyLock

func RemoveProxyLock(dir string) error

RemoveProxyLock removes the proxy lock file.

func SaveProxyLock

func SaveProxyLock(dir string, info ProxyLockInfo) error

SaveProxyLock writes the proxy lock file.

Types

type Lifecycle

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

Lifecycle manages the shared reverse proxy lifecycle.

func NewLifecycle

func NewLifecycle(dir string, desiredPort int) (*Lifecycle, error)

NewLifecycle creates a lifecycle manager for the proxy. If desiredPort is 0, a random available port will be used. If desiredPort is negative, the default port (8080) will be used.

func (*Lifecycle) CA

func (lc *Lifecycle) CA() *proxy.CA

CA returns the CA used for TLS, or nil if TLS is not enabled.

func (*Lifecycle) EnableTLS

func (lc *Lifecycle) EnableTLS() (newCA bool, err error)

EnableTLS enables TLS support by loading or creating a CA. Must be called before EnsureRunning(). Returns true if a new CA was created (caller should print trust instructions).

func (*Lifecycle) EnsureRunning

func (lc *Lifecycle) EnsureRunning() error

EnsureRunning starts the proxy if not already running.

func (*Lifecycle) Port

func (lc *Lifecycle) Port() int

Port returns the port the proxy is running on.

func (*Lifecycle) Routes

func (lc *Lifecycle) Routes() *RouteTable

Routes returns the route table.

func (*Lifecycle) ShouldStop

func (lc *Lifecycle) ShouldStop() bool

ShouldStop returns true if there are no more registered agents.

func (*Lifecycle) Stop

func (lc *Lifecycle) Stop(ctx context.Context) error

Stop stops the proxy if this instance owns it.

type ProxyLockInfo

type ProxyLockInfo struct {
	PID       int       `json:"pid"`
	Port      int       `json:"port"`
	StartedAt time.Time `json:"started_at"`
}

ProxyLockInfo holds information about a running proxy.

func LoadProxyLock

func LoadProxyLock(dir string) (*ProxyLockInfo, error)

LoadProxyLock loads the proxy lock file from the given directory. Returns nil, nil if the lock file doesn't exist.

func (*ProxyLockInfo) IsAlive

func (p *ProxyLockInfo) IsAlive() bool

IsAlive checks if the process is still running.

type ProxyServer

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

ProxyServer wraps the reverse proxy with lifecycle management.

func NewProxyServer

func NewProxyServer(routes *RouteTable) *ProxyServer

NewProxyServer creates a new proxy server.

func (*ProxyServer) EnableTLS

func (ps *ProxyServer) EnableTLS(ca *proxy.CA) error

EnableTLS configures TLS support using the given CA. Must be called before Start().

func (*ProxyServer) Port

func (ps *ProxyServer) Port() int

Port returns the port the server is listening on.

func (*ProxyServer) Start

func (ps *ProxyServer) Start(port int) error

Start starts the proxy server on the given port. If TLS is enabled, the server handles both HTTP and HTTPS on the same port.

func (*ProxyServer) Stop

func (ps *ProxyServer) Stop(ctx context.Context) error

Stop gracefully shuts down the proxy server.

type ReverseProxy

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

ReverseProxy routes requests based on Host header to container services.

func NewReverseProxy

func NewReverseProxy(routes *RouteTable) *ReverseProxy

NewReverseProxy creates a reverse proxy with the given route table.

func (*ReverseProxy) ServeHTTP

func (rp *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles incoming requests and routes them to backends.

type RouteTable

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

RouteTable manages agent -> endpoint -> host:port mappings.

func NewRouteTable

func NewRouteTable(dir string) (*RouteTable, error)

NewRouteTable creates or loads a route table from the given directory.

func (*RouteTable) Add

func (rt *RouteTable) Add(agent string, endpoints map[string]string) error

Add registers routes for an agent.

func (*RouteTable) AgentExists

func (rt *RouteTable) AgentExists(agent string) bool

AgentExists returns true if the agent has registered routes. It reloads routes from disk to pick up changes from other processes.

func (*RouteTable) Agents

func (rt *RouteTable) Agents() []string

Agents returns all registered agent names. It reloads routes from disk to pick up changes from other processes.

func (*RouteTable) Lookup

func (rt *RouteTable) Lookup(agent, endpoint string) (string, bool)

Lookup returns the host:port for an agent's endpoint. It reloads routes from disk to pick up changes from other processes.

func (*RouteTable) LookupDefault

func (rt *RouteTable) LookupDefault(agent string) (string, bool)

LookupDefault returns the first endpoint's address for an agent. It reloads routes from disk to pick up changes from other processes.

func (*RouteTable) Remove

func (rt *RouteTable) Remove(agent string) error

Remove unregisters an agent's routes. If no routes remain, the routes file is deleted.

Jump to

Keyboard shortcuts

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