Documentation
¶
Index ¶
- Variables
- func AnyRelativePath(prefixPath string) string
- func Chain(h http.Handler, middlewares ...Middleware) http.Handler
- func DefaultTransport() *http.Transport
- func SetLogger(l *zap.Logger)
- func StartHealthChecks(backends []*Backend, config HealthCheckConfig)
- type Backend
- type Balancer
- type HealthCheckConfig
- type IPHash
- type LeastConnections
- type ManagementRequest
- type Middleware
- type Proxy
- type RoundRobin
- type Route
- type RouteManager
- func (m *RouteManager) AddRoute(prefixPath string, balancer Balancer) (*Route, error)
- func (m *RouteManager) GetRoute(prefixPath string) (*Route, bool)
- func (m *RouteManager) HandleAddBackends(w http.ResponseWriter, r *http.Request)
- func (m *RouteManager) HandleGetBackend(w http.ResponseWriter, r *http.Request)
- func (m *RouteManager) HandleListBackends(w http.ResponseWriter, r *http.Request)
- func (m *RouteManager) HandleRemoveBackends(w http.ResponseWriter, r *http.Request)
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoHealthyBackends = errors.New("no healthy backends available")
)
Functions ¶
func AnyRelativePath ¶
func Chain ¶
func Chain(h http.Handler, middlewares ...Middleware) http.Handler
Chain links multiple middlewares together to form a single http.Handler.
func DefaultTransport ¶
DefaultTransport returns a http.Transport optimized for reverse proxy usage.
func StartHealthChecks ¶
func StartHealthChecks(backends []*Backend, config HealthCheckConfig)
StartHealthChecks initiate backend health check for the backend server pool.
Types ¶
type Backend ¶
Backend encapsulates the backend server information.
func NewBackend ¶
NewBackend creates a new Backend instance.
func ParseBackends ¶
ParseBackends helper function: converts a list of URL strings into []*Backend
func (*Backend) DecrementActiveConns ¶
func (b *Backend) DecrementActiveConns()
func (*Backend) GetActiveConns ¶
func (*Backend) IncrementActiveConns ¶
func (b *Backend) IncrementActiveConns()
func (*Backend) SetHealthy ¶
func (*Backend) StopHealthCheck ¶
func (b *Backend) StopHealthCheck()
StopHealthCheck stops the health check goroutine associated with this backend.
type Balancer ¶
type Balancer interface {
Next(r *http.Request) (*Backend, error)
GetBackends() []*Backend
AddBackend(b *Backend)
RemoveBackend(b *Backend)
}
Balancer is an interface that must be implemented for all load balancing strategies.
type HealthCheckConfig ¶
type HealthCheckConfig struct {
Interval time.Duration `json:"interval"`
Timeout time.Duration `json:"timeout"`
}
HealthCheckConfig defined the configuration for health check.
type IPHash ¶
type IPHash struct {
// contains filtered or unexported fields
}
func (*IPHash) AddBackend ¶
func (*IPHash) GetBackends ¶
func (*IPHash) RemoveBackend ¶
type LeastConnections ¶
type LeastConnections struct {
// contains filtered or unexported fields
}
func NewLeastConnections ¶
func NewLeastConnections(backends []*Backend) *LeastConnections
func (*LeastConnections) AddBackend ¶
func (lc *LeastConnections) AddBackend(b *Backend)
func (*LeastConnections) GetBackends ¶
func (lc *LeastConnections) GetBackends() []*Backend
func (*LeastConnections) RemoveBackend ¶
func (lc *LeastConnections) RemoveBackend(b *Backend)
type ManagementRequest ¶
type ManagementRequest struct {
PrefixPath string `json:"prefixPath"`
Targets []string `json:"targets"`
HealthCheck HealthCheckConfig `json:"healthCheck"`
}
ManagementRequest is for the management API.
type Middleware ¶
Middleware is a function that takes a http.Handler and returns a http.Handler, used to build a middleware chain.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is a reverse proxy that implements the http.Handler interface.
type RoundRobin ¶
type RoundRobin struct {
// contains filtered or unexported fields
}
func NewRoundRobin ¶
func NewRoundRobin(backends []*Backend) *RoundRobin
func (*RoundRobin) AddBackend ¶
func (r *RoundRobin) AddBackend(b *Backend)
AddBackend implement the Balancer interface
func (*RoundRobin) GetBackends ¶
func (r *RoundRobin) GetBackends() []*Backend
GetBackends implement the Balancer interface
func (*RoundRobin) RemoveBackend ¶
func (r *RoundRobin) RemoveBackend(b *Backend)
RemoveBackend implement the Balancer interface
type Route ¶
type Route struct {
PrefixPath string
Backends []*Backend
Balancer Balancer
Proxy *Proxy
// contains filtered or unexported fields
}
Route holds all components for a specific routing rule.
type RouteManager ¶
type RouteManager struct {
// contains filtered or unexported fields
}
RouteManager manages all routing rules.
func (*RouteManager) AddRoute ¶
func (m *RouteManager) AddRoute(prefixPath string, balancer Balancer) (*Route, error)
AddRoute adds a new routing rule and configures its proxy to strip the given prefix.
func (*RouteManager) GetRoute ¶
func (m *RouteManager) GetRoute(prefixPath string) (*Route, bool)
GetRoute safely retrieves a route.
func (*RouteManager) HandleAddBackends ¶
func (m *RouteManager) HandleAddBackends(w http.ResponseWriter, r *http.Request)
HandleAddBackends handles the HTTP request to add new backends to a route.
func (*RouteManager) HandleGetBackend ¶
func (m *RouteManager) HandleGetBackend(w http.ResponseWriter, r *http.Request)
HandleGetBackend handles the HTTP request to get a backend in a route.
func (*RouteManager) HandleListBackends ¶
func (m *RouteManager) HandleListBackends(w http.ResponseWriter, r *http.Request)
HandleListBackends handles the HTTP request to list backends in a route.
func (*RouteManager) HandleRemoveBackends ¶
func (m *RouteManager) HandleRemoveBackends(w http.ResponseWriter, r *http.Request)
HandleRemoveBackends handles the HTTP request to remove backends from a route.