Documentation
¶
Index ¶
- Constants
- Variables
- func BackendNodeStats(n []*BackendNode) []balancer.Statistics
- type ACL
- type ACLS
- type Backend
- func (b *Backend) AddBackendNode(n *BackendNode)
- func (b *Backend) ClearStats()
- func (b *Backend) GetBackend() (*BackendNode, error)
- func (b *Backend) GetBackendNodeBalanced(backendpool, ip, sticky, balancemode string) (*BackendNode, healthcheck.Status, error)
- func (b *Backend) GetBackendNodeByID(uuid string) (*BackendNode, error)
- func (b *Backend) GetBackendsUUID() (n []string, err error)
- func (b *Backend) LoadErrorPage(e ErrorPage) error
- func (b *Backend) RemoveBackendNode(nodeid int)
- func (b *Backend) RemoveNodeByID(uuid string) error
- func (b *Backend) SetACL(direction string, acl []ACL)
- func (b *Backend) SetRules(direction string, rule []string)
- func (b *Backend) UpdateBackendNode(nodeid int, status healthcheck.Status)
- type BackendNode
- type ErrorPage
- type Listener
- func (l *Listener) AddBackend(uuid string, name string, balancemode string, connectmode string, ...)
- func (l *Listener) Debug()
- func (l *Listener) FindAllHostNames() []string
- func (l *Listener) FindBackendByHost(req string) (string, *Backend)
- func (l *Listener) GetBackend() (*Backend, error)
- func (l *Listener) GetBackendStats(backendName string) *balancer.Statistics
- func (l *Listener) Handler(client net.Conn)
- func (l *Listener) LoadErrorPage(e ErrorPage) error
- func (l *Listener) LoadMaintenancePage(e ErrorPage) error
- func (l *Listener) NewHTTPProxy() *httputil.ReverseProxy
- func (l *Listener) NewTCPProxy() (net.Listener, error)
- func (l *Listener) ProcessInboundRules(rules []string, req *http.Request, res *http.Response) error
- func (l *Listener) ProcessOutboundRules(rules []string, req *http.Request, res *http.Response) error
- func (l *Listener) ProcessPreInboundRules(rules []string, req *http.Request) error
- func (l *Listener) RemoveBackend(name string)
- func (l *Listener) SetListener(mode string, sourceIP string, ip string, port int, maxConnections int, ...)
- func (l *Listener) Start()
- func (l *Listener) Stop()
- func (l *Listener) TCPProxy(n net.Listener)
- func (l *Listener) UpdateBackend(uuid string, name string, balancemode string, connectmode string, ...)
Constants ¶
const ( // YES when yes simply isn't enough YES = "yes" // HTTP string HTTP = "http" // HTTPS string HTTPS = "https" )
Variables ¶
var ( // SERVERCOOKIE is the cookie string set by servers to set cookies on client SERVERCOOKIE = "Set-Cookie" // CLIENTCOOKIE is the cookie string set by clients to send cookies to the server CLIENTCOOKIE = "Cookie" )
Functions ¶
func BackendNodeStats ¶
func BackendNodeStats(n []*BackendNode) []balancer.Statistics
BackendNodeStats gets statistics for backend nodes
Types ¶
type ACL ¶
type ACL struct { Action string `json:"action" toml:"action"` // remove, replace, add, deny HeaderKey string `json:"header_key" toml:"header_key"` // header key HeaderValue string `json:"header_value" toml:"header_value"` // header value CookieKey string `json:"cookie_key" toml:"cookie_key"` // cookie key CookieValue string `json:"cookie_value" toml:"cookie_value"` // cookie value CookiePath string `json:"cookie_path" toml:"cookie_path"` // cookie path CookieExpire duration `json:"cookie_expire" toml:"cookie_expire"` // cookie expiry date CookieSecure *bool `json:"cookie_secure" toml:"cookie_secure"` // cookie secure Cookiehttponly *bool `json:"cookie_httponly" toml:"cookie_httponly"` // cookie httponly ConditionType string `json:"conditiontype" toml:"conditiontype"` // header, cookie, other? ConditionMatch string `json:"conditionmatch" toml:"conditionmatch"` // header text (e.g. /^Content-Type: (.*)/(.*)$/i) URLMatch string `json:"urlmatch" toml:"urlmatch"` // url match #^/(.*)# URLRewrite string `json:"urlrewrite" toml:"urlrewrite"` // url rewrite /Other/Path/$1 StatusCode int `json:"status_code" toml:"status_code"` // status code URLPath string `json:"url_path" toml:"url_path"` // request path to match this acl if provided CIDRS []string `json:"cidrs" toml:"cidrs"` // network cidr }
ACL is used by HTTP proxies for setting/removing headers, cookies or status code
func (ACL) ProcessRequest ¶
ProcessRequest processes ACL's for request
func (ACL) ProcessResponse ¶
ProcessResponse processes ACL's for response
func (ACL) ProcessTCPRequest ¶
ProcessTCPRequest processes ACL's for tcp proxy
type ACLS ¶
type ACLS []ACL
ACLS contains a list of ACL
func (ACLS) CountActions ¶
CountActions returns the number of matches of action are in the ACL's
type Backend ¶
type Backend struct { UUID string BalanceMode string ConnectMode string InboundACL ACLS OutboundACL ACLS PreInboundRule []string InboundRule []string OutboundRule []string Statistics *balancer.Statistics Nodes []*BackendNode Hostname []string Fallback string Uptime time.Time ErrorPage ErrorPage MaintenancePage ErrorPage // contains filtered or unexported fields }
Backend is a backend where the proxy can connect to
func NewBackend ¶
func NewBackend(uuid string, balancemode string, connectmode string, hostname []string, maxconnections int, errorPage ErrorPage, maintenancePage ErrorPage) *Backend
NewBackend creates a new backend
func (*Backend) AddBackendNode ¶
func (b *Backend) AddBackendNode(n *BackendNode)
AddBackendNode adds a backend to the listener
func (*Backend) ClearStats ¶
func (b *Backend) ClearStats()
ClearStats clears the statistics of all nodes of a backend
func (*Backend) GetBackend ¶
func (b *Backend) GetBackend() (*BackendNode, error)
GetBackend Return the first backend
func (*Backend) GetBackendNodeBalanced ¶
func (b *Backend) GetBackendNodeBalanced(backendpool, ip, sticky, balancemode string) (*BackendNode, healthcheck.Status, error)
GetBackendNodeBalanced returns a single backend node, based on balancer proto
func (*Backend) GetBackendNodeByID ¶
func (b *Backend) GetBackendNodeByID(uuid string) (*BackendNode, error)
GetBackendNodeByID Return backend node by ID
func (*Backend) GetBackendsUUID ¶
GetBackendsUUID Return backend node by ID
func (*Backend) LoadErrorPage ¶
LoadErrorPage preloads the error page
func (*Backend) RemoveBackendNode ¶
RemoveBackendNode remove a backend node from the listener
func (*Backend) RemoveNodeByID ¶
RemoveNodeByID remove backend node by ID
func (*Backend) UpdateBackendNode ¶
func (b *Backend) UpdateBackendNode(nodeid int, status healthcheck.Status)
UpdateBackendNode update a backend node with a new status
type BackendNode ¶
type BackendNode struct { UUID string IP string Hostname string Port int Statistics *balancer.Statistics Uptime time.Time MaxConnections int Preference int Weight int Status healthcheck.Status LocalTopology string `json:"local_topology" toml:"local_topology"` // overrides localnetwork LocalNetwork []string `json:"local_network" toml:"local_network"` // used for topology based loadbalancing }
BackendNode is a backendnode where the proxy can connect to
func NewBackendNode ¶
func NewBackendNode(UUID string, IP string, hostname string, port int, maxconnections int, topology []string, preference int, weight int, status healthcheck.Status) *BackendNode
NewBackendNode creates a new node for a proxy backend
func (*BackendNode) Name ¶
func (a *BackendNode) Name() string
Name returns the node name, either hostname or ip
type ErrorPage ¶
type ErrorPage struct { File string `json:"file" toml:"file"` // alternative error page to show StatusCode int `json:"statuscode" toml:"statuscode"` // error code to give StatusMessage string `json:"statusmessage" toml:"statusmessage"` // error message to apply TriggerThreshold int `json:"trigger_threshold" toml:"trigger_threshold"` // Theshold at which to trigger the error page (generally 500 and up) // contains filtered or unexported fields }
ErrorPage contains the page to show on errors
type Listener ¶
type Listener struct { UUID string Name string SourceIP string IP string Port int ListenerMode string // Protocol the listener expects HTTPProto int // HTTP Version Protocol the listener expects Backends map[string]*Backend TLSConfig *tls.Config // TLS Config MaxConnections int Statistics *balancer.Statistics ErrorPage ErrorPage MaintenancePage ErrorPage ReadTimeout int // Timeout in seconds to wait for the client sending the request - https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/ WriteTimeout int // Timeout in seconds to wait for server reply to client Uptime time.Time OCSPStapling string // use OCSP Stapling // contains filtered or unexported fields }
Listener contains the config for the proxy listener
func (*Listener) AddBackend ¶
func (l *Listener) AddBackend(uuid string, name string, balancemode string, connectmode string, hostname []string, maxconnections int, errorPage ErrorPage, maintenancePage ErrorPage)
AddBackend adds a backend to an existing proxy
func (*Listener) FindAllHostNames ¶
FindAllHostNames searches for matching backend by hostname requested
func (*Listener) FindBackendByHost ¶
FindBackendByHost searches for matching backend by hostname requested
func (*Listener) GetBackend ¶
GetBackend Return the first backend
func (*Listener) GetBackendStats ¶
func (l *Listener) GetBackendStats(backendName string) *balancer.Statistics
GetBackendStats gets the combined statistics from all nodes of a backend
func (*Listener) LoadErrorPage ¶
LoadErrorPage preloads the error page
func (*Listener) LoadMaintenancePage ¶
LoadMaintenancePage preloads the error page
func (*Listener) NewHTTPProxy ¶
func (l *Listener) NewHTTPProxy() *httputil.ReverseProxy
NewHTTPProxy Create a HTTP proxy
func (*Listener) NewTCPProxy ¶
NewTCPProxy creates a new TCP proxy
func (*Listener) ProcessInboundRules ¶
ProcessInboundRules runs the rules script, and modified the given request accordingly Inbound rules apply only on the initial request before passing it on to a backend res can be nil, we need to ensure its only filled if we did set a response on the inbound rule
func (*Listener) ProcessOutboundRules ¶
func (l *Listener) ProcessOutboundRules(rules []string, req *http.Request, res *http.Response) error
ProcessOutboundRules runs the rules script, and modified the given request/response accordingly Outbound rules are applied when contacting the backend, or replying the response to a client res cannot be nil at this point
func (*Listener) ProcessPreInboundRules ¶
ProcessPreInboundRules runs the rules script, and modified the given request accordingly PreInbound rules apply only on the initial request before selecting a backend
func (*Listener) RemoveBackend ¶
RemoveBackend removes a backend from the listener
func (*Listener) SetListener ¶
func (l *Listener) SetListener(mode string, sourceIP string, ip string, port int, maxConnections int, tlsConfig *tls.Config, readTimeout int, writeTimeout int, httpProto int, ocspStapling string)
SetListener sets all listener config for the proxy