Documentation
¶
Overview ¶
Package sticky provides a session-aware reverse proxy for horizontally scaled Engine.IO and Socket.IO servers.
Index ¶
- type BackendStats
- type LoadBalancingMethod
- type Options
- type Router
- func (r *Router) AddBackend(id string, target *url.URL) error
- func (r *Router) BackendForSession(sid string) (string, bool)
- func (r *Router) Bind(sid, backendID string) bool
- func (r *Router) Close() error
- func (r *Router) RemoveBackend(id string)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Stats() []BackendStats
- func (r *Router) Unbind(sid string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackendStats ¶
BackendStats is a point-in-time backend snapshot.
type LoadBalancingMethod ¶
type LoadBalancingMethod string
LoadBalancingMethod controls the selection of a backend for a new Engine.IO session. Existing sessions are always routed to their owning backend.
const ( Random LoadBalancingMethod = "random" RoundRobin LoadBalancingMethod = "round-robin" LeastConnection LoadBalancingMethod = "least-connection" )
type Options ¶
type Options struct {
// LoadBalancingMethod defaults to LeastConnection.
LoadBalancingMethod LoadBalancingMethod
// SessionTTL removes inactive polling mappings. Active polling clients touch
// their mapping on every request. A zero value uses two minutes.
SessionTTL time.Duration
// SweepInterval controls stale mapping cleanup. A zero value is derived from
// SessionTTL and capped at 30 seconds.
SweepInterval time.Duration
// ErrorHandler optionally handles proxy failures. The default returns 502.
ErrorHandler func(http.ResponseWriter, *http.Request, error)
// DebugHeader, when set, receives the selected backend ID. It is intended for
// tests and diagnostics and is disabled by default.
DebugHeader string
}
Options configures a Router.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router routes every request carrying an Engine.IO sid to the backend that created that sid. It can be used in front of several Go processes together with a cluster adapter (for example the Unix or Redis adapter).
func (*Router) AddBackend ¶
AddBackend registers or atomically replaces a backend.
func (*Router) BackendForSession ¶
BackendForSession returns the current owner of sid.
func (*Router) RemoveBackend ¶
RemoveBackend removes a backend and all mappings owned by it.
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements http.Handler, including WebSocket upgrade proxying.
func (*Router) Stats ¶
func (r *Router) Stats() []BackendStats
Stats returns a stable, ID-sorted snapshot.