proxy

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package proxy provides HTTP/HTTPS reverse proxy functionality.

It handles:

  • Dynamic routing based on hostname and path
  • TLS termination with auto-generated certificates
  • Real-time dashboard with Server-Sent Events (SSE)
  • Health check and status endpoints

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildInfo added in v0.4.0

type BuildInfo struct {
	Version string `json:"version"`
	Commit  string `json:"commit"`
	Date    string `json:"date"`
	BuiltBy string `json:"built_by"`
}

BuildInfo contains build metadata

type CertInfo

type CertInfo struct {
	Exists        bool       `json:"exists"`
	ValidUntil    *time.Time `json:"valid_until,omitempty"`
	DaysRemaining *int       `json:"days_remaining,omitempty"`
	Subject       string     `json:"subject,omitempty"`
	DNSNames      []string   `json:"dns_names,omitempty"` // server cert only
}

CertInfo contains details about a specific certificate

type CertificateStatus

type CertificateStatus struct {
	AutoGenerated bool      `json:"auto_generated"`
	Directory     string    `json:"directory"`
	CA            *CertInfo `json:"ca"`
	Server        *CertInfo `json:"server"`
}

CertificateStatus contains information about TLS certificates

type DockerStatus

type DockerStatus struct {
	Connected  bool     `json:"connected"`
	Networks   []string `json:"networks"`
	APIVersion string   `json:"api_version,omitempty"`
}

DockerStatus contains Docker connection information

type Handler

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

Handler is the main HTTP handler for the reverse proxy

func NewHandler

func NewHandler(router *Router, dockerClient *docker.Client, dashboardHost string, baseDomain string, statusConfig *StatusConfig, projectStore *project.Store) *Handler

NewHandler creates a new proxy handler

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler

type LogBuffer added in v0.6.0

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

LogBuffer is a thread-safe ring buffer for request logs

func NewLogBuffer added in v0.6.0

func NewLogBuffer(capacity int) *LogBuffer

NewLogBuffer creates a new log buffer with the specified capacity

func (*LogBuffer) Add added in v0.6.0

func (lb *LogBuffer) Add(log RequestLog)

Add adds a new log entry to the buffer

func (*LogBuffer) Clear added in v0.6.0

func (lb *LogBuffer) Clear()

Clear removes all logs from the buffer

func (*LogBuffer) List added in v0.6.0

func (lb *LogBuffer) List() []RequestLog

List returns all logs in the buffer (oldest first)

func (*LogBuffer) ListRecent added in v0.6.0

func (lb *LogBuffer) ListRecent(n int) []RequestLog

ListRecent returns the most recent n logs (newest first)

func (*LogBuffer) Subscribe added in v0.6.0

func (lb *LogBuffer) Subscribe() (chan RequestLog, func())

Subscribe creates a channel that receives new log entries

func (*LogBuffer) SubscriberCount added in v0.6.0

func (lb *LogBuffer) SubscriberCount() int

SubscriberCount returns the number of active subscribers

type ProxyStatus

type ProxyStatus struct {
	RoutesCount    int    `json:"routes_count"`
	DashboardHost  string `json:"dashboard_host"`
	BaseDomain     string `json:"base_domain"`
	HTTPPort       int    `json:"http_port"`
	HTTPSPort      int    `json:"https_port"`
	SSESubscribers int    `json:"sse_subscribers"`
}

ProxyStatus contains proxy configuration and state

type RedirectHandler

type RedirectHandler struct {
	HTTPSPort int
}

RedirectHandler redirects HTTP to HTTPS

func (*RedirectHandler) ServeHTTP

func (h *RedirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler for HTTP->HTTPS redirect

type RequestLog added in v0.6.0

type RequestLog struct {
	ID        int64     `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Method    string    `json:"method"`
	Host      string    `json:"host"`
	Path      string    `json:"path"`
	Status    int       `json:"status"`
	Duration  int64     `json:"duration_ms"` // milliseconds
	Service   string    `json:"service"`
	IsMock    bool      `json:"is_mock,omitempty"`
}

RequestLog represents a single request log entry

type Route

type Route struct {
	Hostname   string
	PathPrefix string
	Backend    *docker.Backend
}

Route represents a single route configuration

type RouteEvent added in v0.4.0

type RouteEvent struct {
	Type   string      `json:"type"`   // "routes"
	Routes []RouteInfo `json:"routes"` // Current route list
}

RouteEvent represents a route change event for SSE subscribers

type RouteInfo

type RouteInfo struct {
	Hostname      string `json:"hostname"`
	PathPrefix    string `json:"pathPrefix,omitempty"`
	Target        string `json:"target"`
	ContainerID   string `json:"containerId"`
	ContainerName string `json:"containerName"`
	ServiceName   string `json:"serviceName"`
	Warning       string `json:"warning,omitempty"`
	Network       string `json:"network,omitempty"`
}

RouteInfo is a display-friendly route representation

func (RouteInfo) String

func (ri RouteInfo) String() string

type Router

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

Router manages routes and provides thread-safe access

func NewRouter

func NewRouter() *Router

NewRouter creates a new route manager

func (*Router) AddBackend

func (r *Router) AddBackend(backend *docker.Backend)

AddBackend adds or updates a route for a backend

func (*Router) ListRoutes

func (r *Router) ListRoutes() []RouteInfo

ListRoutes returns all current routes for display

func (*Router) Lookup

func (r *Router) Lookup(hostname, path string) *Route

Lookup finds a route for a given hostname and path

func (*Router) RemoveBackend

func (r *Router) RemoveBackend(containerID string)

RemoveBackend removes routes for a container

func (*Router) RemoveProject

func (r *Router) RemoveProject(projectName string)

RemoveProject removes all routes for a given project

func (*Router) Subscribe added in v0.4.0

func (r *Router) Subscribe(ctx context.Context) (<-chan RouteEvent, func())

Subscribe creates a new SSE subscriber and returns the event channel and cleanup function. The cleanup function must be called when the subscriber disconnects.

func (*Router) SubscriberCount added in v0.4.0

func (r *Router) SubscriberCount() int

SubscriberCount returns the number of active SSE subscribers

type StatusConfig

type StatusConfig struct {
	Version       string
	Commit        string
	Date          string
	BuiltBy       string
	StartTime     time.Time
	CertsDir      string
	AutoGenerated bool
	Networks      []string // Docker networks being watched
	BaseDomain    string
	HTTPPort      int
	HTTPSPort     int
}

StatusConfig contains configuration for the status endpoint

type StatusResponse

type StatusResponse struct {
	Build         BuildInfo         `json:"build"`
	UptimeSeconds int64             `json:"uptime_seconds"`
	Certificates  CertificateStatus `json:"certificates"`
	Docker        DockerStatus      `json:"docker"`
	Proxy         ProxyStatus       `json:"proxy"`
	Health        string            `json:"health"`
}

StatusResponse represents the overall status of roji

type Subscriber added in v0.4.0

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

Subscriber represents an SSE subscriber

Jump to

Keyboard shortcuts

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