proxy

package
v0.1.0-beta.49 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 24 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) CertificateCount

func (cm *CertManager) CertificateCount() int

CertificateCount returns the number of loaded certificates.

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) HasCertificate

func (cm *CertManager) HasCertificate(domain string) bool

HasCertificate checks if a certificate exists for the given domain.

func (*CertManager) ReloadCertificates

func (cm *CertManager) ReloadCertificates() error

ReloadCertificates reloads all certificates from disk.

func (*CertManager) SetDomainResolver

func (cm *CertManager) SetDomainResolver(resolver DomainResolver)

SetDomainResolver sets the resolver used for alias lookups.

func (*CertManager) Stop

func (cm *CertManager) Stop()

Stop stops the certificate manager (no-op, retained for interface compatibility).

type Config

type Config struct {
	// Routes maps canonical domains (lowercase) to their route configurations.
	Routes map[string]*Route
	// APIDomain is the domain for the haloy API (lowercase).
	APIDomain string
}

Config holds the proxy configuration.

func BuildConfigFromDeployments

func BuildConfigFromDeployments(deployments []DeploymentInfo, apiDomain string) (*Config, error)

BuildConfigFromDeployments creates a proxy config from deployment information.

func BuildConfigFromHaloydDeployments

func BuildConfigFromHaloydDeployments(deployments map[string]HaloydDeployment, apiDomain string) (*Config, error)

BuildConfigFromHaloydDeployments converts the haloyd deployment format to proxy config.

type DeploymentInfo

type DeploymentInfo struct {
	AppName   string
	Canonical string
	Aliases   []string
	Instances []InstanceInfo
}

BuildRoutesFromDeployments is a helper function to build routes from a deployment map. This function bridges the gap between the deployment manager's data structure and the proxy's route configuration.

type DomainResolver

type DomainResolver interface {
	ResolveCanonical(domain string) (string, bool)
}

DomainResolver resolves alias domains to canonical domains.

type HaloydDeployment

type HaloydDeployment struct {
	AppName   string
	Domains   []HaloydDomain
	Instances []HaloydInstance
}

ConvertDeployments is a convenience type alias for the deployment map format used by haloyd's DeploymentManager.

type HaloydDomain

type HaloydDomain struct {
	Canonical string
	Aliases   []string
}

type HaloydInstance

type HaloydInstance struct {
	IP   string
	Port string
}

type InstanceInfo

type InstanceInfo struct {
	IP   string
	Port string
}

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, apiHandler http.Handler) *Proxy

New creates a new Proxy instance.

func (*Proxy) GetConfig

func (p *Proxy) GetConfig() *Config

GetConfig returns the current proxy configuration.

func (*Proxy) ResolveCanonical

func (p *Proxy) ResolveCanonical(domain string) (string, bool)

ResolveCanonical resolves an alias domain to its canonical domain.

func (*Proxy) Shutdown

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

Shutdown gracefully shuts down both HTTP and HTTPS servers.

func (*Proxy) Start

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

Start starts both HTTP and HTTPS servers.

func (*Proxy) UpdateConfig

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

UpdateConfig atomically updates the proxy configuration.

type Route

type Route struct {
	Canonical string
	Aliases   []string
	Backends  []Backend
}

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 creates the final proxy configuration. Returns an error if duplicate aliases are detected across routes.

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