Documentation
¶
Overview ¶
Package routing provides hostname-based reverse proxy routing.
Index ¶
- func RemoveProxyLock(dir string) error
- func SaveProxyLock(dir string, info ProxyLockInfo) error
- type Lifecycle
- func (lc *Lifecycle) CA() *proxy.CA
- func (lc *Lifecycle) EnableTLS() (newCA bool, err error)
- func (lc *Lifecycle) EnsureRunning() error
- func (lc *Lifecycle) Port() int
- func (lc *Lifecycle) Routes() *RouteTable
- func (lc *Lifecycle) ShouldStop() bool
- func (lc *Lifecycle) Stop(ctx context.Context) error
- type ProxyLockInfo
- type ProxyServer
- type ReverseProxy
- type RouteTable
- func (rt *RouteTable) Add(agent string, endpoints map[string]string) error
- func (rt *RouteTable) AgentExists(agent string) bool
- func (rt *RouteTable) Agents() []string
- func (rt *RouteTable) Lookup(agent, endpoint string) (string, bool)
- func (rt *RouteTable) LookupDefault(agent string) (string, bool)
- func (rt *RouteTable) Remove(agent string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RemoveProxyLock ¶
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 ¶
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) EnableTLS ¶
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 ¶
EnsureRunning starts the proxy if not already running.
func (*Lifecycle) Routes ¶
func (lc *Lifecycle) Routes() *RouteTable
Routes returns the route table.
func (*Lifecycle) ShouldStop ¶
ShouldStop returns true if there are no more registered agents.
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.
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.