proxy

package
v0.1.0-beta.69 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	IP   string
	Port string
}

Backend represents a backend server that can receive traffic.

type CertLoader

type CertLoader interface {
	GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)
}

CertLoader is an interface for loading TLS certificates.

type CertManager

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

CertManager manages TLS certificates for the proxy. It loads certificates from disk and reloads when explicitly told to via ReloadCertificates().

func NewCertManager

func NewCertManager(certDir string, logger *slog.Logger) (*CertManager, error)

NewCertManager creates a new certificate manager.

func (*CertManager) CertCount

func (cm *CertManager) CertCount() int

CertCount returns the number of certificates currently cached.

func (*CertManager) GetCertificate

func (cm *CertManager) GetCertificate(hello *tls.ClientHelloInfo) (*tls.Certificate, error)

GetCertificate implements the tls.Config.GetCertificate callback. It returns the certificate for the given SNI hostname.

func (*CertManager) ReloadCertificates

func (cm *CertManager) ReloadCertificates() error

ReloadCertificates reloads all certificates from disk.

func (*CertManager) SetRouteTable

func (cm *CertManager) SetRouteTable(config *Config)

SetRouteTable updates the routing snapshot used for alias resolution and known-host checks. Proxy.UpdateConfig calls this automatically.

type Config

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

Config is an immutable, validated routing snapshot. Build one with RouteBuilder; the zero value routes nothing.

func ConfigFromSnapshot

func ConfigFromSnapshot(snap *proxywire.Snapshot) (*Config, error)

ConfigFromSnapshot validates and converts a wire snapshot into an immutable routing Config, applying the same duplicate-domain validation as RouteBuilder. The round-robin state of each route starts fresh.

func (*Config) APIBackend

func (c *Config) APIBackend() (Backend, bool)

APIBackend returns the control plane's API listener address and whether one is configured.

func (*Config) APIDomain

func (c *Config) APIDomain() string

APIDomain returns the domain for the haloy API (lowercase).

func (*Config) FindRoute

func (c *Config) FindRoute(host string) *Route

FindRoute returns the route for the given host (canonical or alias), or nil.

func (*Config) IsKnownHost

func (c *Config) IsKnownHost(host string) bool

IsKnownHost reports whether the host is a routed domain (canonical or alias) or the API domain.

func (*Config) ResolveCanonical

func (c *Config) ResolveCanonical(domain string) (string, bool)

ResolveCanonical resolves a domain (canonical or alias) to its canonical domain.

func (*Config) RouteCount

func (c *Config) RouteCount() int

RouteCount returns the number of routes (canonical domains).

type Proxy

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

Proxy is an HTTP reverse proxy with TLS termination and host-based routing.

func New

func New(logger *slog.Logger, certLoader CertLoader) *Proxy

New creates a new Proxy instance.

func (*Proxy) Err

func (p *Proxy) Err() <-chan error

Err returns a channel that receives fatal listener errors occurring after Start returned. A value on this channel means the proxy is no longer serving traffic and the process should exit.

func (*Proxy) GetConfig

func (p *Proxy) GetConfig() *Config

GetConfig returns the current proxy configuration.

func (*Proxy) Shutdown

func (p *Proxy) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down both HTTP and HTTPS servers, then waits for active WebSocket tunnels to drain. Tunnels still open when ctx expires are force-closed.

func (*Proxy) Start

func (p *Proxy) Start(httpAddr, httpsAddr string) error

Start binds the HTTP and HTTPS listeners and starts serving. A bind failure is returned immediately; errors after that are delivered on Err().

func (*Proxy) UpdateConfig

func (p *Proxy) UpdateConfig(config *Config)

UpdateConfig atomically updates the proxy configuration. If the cert loader uses routing information (alias resolution, known-host checks), the new snapshot is forwarded to it as well.

type Route

type Route struct {
	Canonical string
	Aliases   []string
	Backends  []Backend
	// contains filtered or unexported fields
}

Route represents a domain route configuration.

type RouteBuilder

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

RouteBuilder helps build proxy routes from deployment information.

func NewRouteBuilder

func NewRouteBuilder() *RouteBuilder

NewRouteBuilder creates a new route builder.

func (*RouteBuilder) AddRoute

func (rb *RouteBuilder) AddRoute(canonical string, aliases []string, backends []Backend)

AddRoute adds a route for an application.

func (*RouteBuilder) Build

func (rb *RouteBuilder) Build() (*Config, error)

Build validates the routes and creates the final proxy configuration with a flat host lookup index. It returns an error if a domain is used as both a canonical domain and an alias, or as an alias of multiple routes.

func (*RouteBuilder) SetAPIBackend

func (rb *RouteBuilder) SetAPIBackend(ip, port string)

SetAPIBackend sets the control plane's API listener address, which the proxy forwards API-domain and localhost API traffic to.

func (*RouteBuilder) SetAPIDomain

func (rb *RouteBuilder) SetAPIDomain(domain string)

SetAPIDomain sets the API domain for the configuration.

Jump to

Keyboard shortcuts

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