proxy

package
v0.0.0-...-0e5caaa Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chain

func Chain(handler http.Handler, middlewares ...func(http.Handler) http.Handler) http.Handler

Middleware chainer This will apply middlewares in the order they appear in the list

func LoggingMiddleware

func LoggingMiddleware(logger *logging.Logger, next http.Handler) http.Handler

func MetricsMiddleware

func MetricsMiddleware(metrics *Metrics, next http.Handler) http.Handler

Middleware to record metrics for the request

func RecoveryMiddleware

func RecoveryMiddleware(logging *logging.Logger, next http.Handler) http.Handler

Middleware to recover from panics and log the error This will prevent the entire proxy from crashing

func TracingMiddleware

func TracingMiddleware(next http.Handler) http.Handler

Types

type BackendConfig

type BackendConfig struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
}

type Config

type Config struct {
	Proxy        ProxyConfig        `yaml:"proxy"`
	ControlPlane ControlPlaneConfig `yaml:"control_plane"`
}

func LoadConfig

func LoadConfig(filepath string) (*Config, error)

Load Configuration from YAML

func (*Config) GetBackendURL

func (c *Config) GetBackendURL() string

func (*Config) Validate

func (c *Config) Validate() error

type ControlPlaneClient

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

This manages the connection to the control plane.

func NewControlPlaneClient

func NewControlPlaneClient(config *Config, logger *logging.Logger) *ControlPlaneClient

func (*ControlPlaneClient) Close

func (c *ControlPlaneClient) Close() error

func (*ControlPlaneClient) Connect

func (c *ControlPlaneClient) Connect(ctx context.Context) error

func (*ControlPlaneClient) GetConfig

func (c *ControlPlaneClient) GetConfig() *pb.ConfigUpdate

func (*ControlPlaneClient) Register

func (*ControlPlaneClient) StartConfigStream

func (c *ControlPlaneClient) StartConfigStream(ctx context.Context) (<-chan struct{}, <-chan error, error)

type ControlPlaneConfig

type ControlPlaneConfig struct {
	Address string `yaml:"address"`
}

type Handler

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

Proxy struct, a reverse proxy reference and a config reference

func NewHandler

func NewHandler(config *Config, logger *logging.Logger) (*Handler, error)

Builds a new Handler

func (*Handler) ServeHTTP

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

Serve through the reverse Proxy

type Metrics

type Metrics struct {

	// Counter for the total number of requests (by service and status code)
	RequestsTotal *prometheus.CounterVec

	// Tracks request latency distribution
	RequestDuration *prometheus.HistogramVec

	// Tracks how many requests are currently being handled by the proxy
	RequestsInFlight prometheus.Gauge

	// Tracks the number of errors (by type)
	ErrorsTotal *prometheus.CounterVec
}

func NewMetrics

func NewMetrics() *Metrics

func (*Metrics) DecInFlight

func (m *Metrics) DecInFlight()

Decrement the number of requests in flight

func (*Metrics) IncInFlight

func (m *Metrics) IncInFlight()

Increment the number of requests in flight

func (*Metrics) RecordError

func (m *Metrics) RecordError(service string, errorType string)

Record an error (by service and type)

func (*Metrics) RecordRequest

func (m *Metrics) RecordRequest(service string, statusCode int, durationSeconds float64)

Record a request (by service and status code)

type ProxyConfig

type ProxyConfig struct {
	ID            string        `yaml:"id"`
	Version       string        `yaml:"version"`
	ListenPort    int           `yaml:"listen_port"`
	AdvertiseAddr string        `yaml:"advertise_addr"`
	Backend       BackendConfig `yaml:"backend"`
	Timeout       TimeoutConfig `yaml:"timeout"`
}

type Server

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

func NewServer

func NewServer(config *Config, logger *logging.Logger) (*Server, error)

func (*Server) Shutdown

func (s *Server) Shutdown(timeout time.Duration) error

Handle Server closing gracefully

func (*Server) Start

func (s *Server) Start() error

Starts the Server: will run till blocked

type TimeoutConfig

type TimeoutConfig struct {
	ReadTimeout  time.Duration `yaml:"read_timeout"`
	WriteTimeout time.Duration `yaml:"write_timeout"`
	IdleTimeout  time.Duration `yaml:"idle_timeout"`
}

Jump to

Keyboard shortcuts

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