Documentation ¶
Index ¶
- Constants
- func BackendName(routeName string, serviceName string) string
- func FilterName(routeName string, filterDestination string) string
- func FrontendName(routeName string, serviceName string) string
- func RouteName(routeName string, serviceName string) string
- func ServerName(routeName string, serviceName string) string
- func ServiceName(routeName string, serviceName string) string
- func Validate(s interface{}) (bool, error)
- type Backend
- type Config
- func (c *Config) AddBackend(backend *Backend) *Error
- func (c *Config) AddFilter(frontend string, filter *Filter) error
- func (c *Config) AddFrontend(frontend *Frontend) *Error
- func (c *Config) AddRoute(route Route) *Error
- func (c *Config) AddRouteServices(routeName string, services []*Service) *Error
- func (c *Config) AddServer(backendName string, server *ServerDetail) *Error
- func (c *Config) AddServiceServer(routeName string, serviceName string, server *Server) *Error
- func (c *Config) BackendExists(name string) bool
- func (c *Config) BackendUsed(name string) *Error
- func (c *Config) BeginReadTrans()
- func (c *Config) BeginWriteTrans()
- func (c *Config) DeleteBackend(name string) *Error
- func (c *Config) DeleteFilter(frontendName string, filterName string) *Error
- func (c *Config) DeleteFrontend(name string) *Error
- func (c *Config) DeleteRoute(name string) *Error
- func (c *Config) DeleteRouteService(routeName string, serviceName string) *Error
- func (c *Config) DeleteServer(backendName string, serverName string) *Error
- func (c *Config) DeleteServiceServer(routeName string, serviceName string, serverName string) *Error
- func (c *Config) EndReadTrans()
- func (c *Config) EndWriteTrans()
- func (c *Config) FrontendExists(name string) bool
- func (c *Config) GetBackend(backend string) (*Backend, *Error)
- func (c *Config) GetBackends() []*Backend
- func (c *Config) GetConfigFromDisk() error
- func (c *Config) GetFilters(frontend string) []*Filter
- func (c *Config) GetFrontend(name string) (*Frontend, *Error)
- func (c *Config) GetFrontends() []*Frontend
- func (c *Config) GetRoute(name string) (Route, *Error)
- func (c *Config) GetRouteService(routeName string, serviceName string) (*Service, *Error)
- func (c *Config) GetRouteServices(name string) ([]*Service, *Error)
- func (c *Config) GetRoutes() []Route
- func (c *Config) GetServer(backendName string, serverName string) (*ServerDetail, *Error)
- func (c *Config) GetServers(backendName string) ([]*ServerDetail, *Error)
- func (c *Config) GetServiceServer(routeName string, serviceName string, serverName string) (*Server, *Error)
- func (c *Config) GetServiceServers(routeName string, serviceName string) ([]*Server, *Error)
- func (c *Config) InitializeConfig()
- func (c *Config) Persist() error
- func (c *Config) Render() error
- func (c *Config) RenderAndPersist() error
- func (c *Config) RouteExists(name string) bool
- func (c *Config) ServerExists(routeName string, serviceName string, serverName string) bool
- func (c *Config) ServiceExists(routeName string, serviceName string) bool
- func (c *Config) SetWeight(backend string, server string, weight int) *Error
- func (c *Config) UpdateConfig(config *Config) *Error
- func (c *Config) UpdateRoute(name string, route *Route) *Error
- func (c *Config) UpdateRouteService(routeName string, serviceName string, service *Service) *Error
- func (c *Config) UpdateRouteServices(routeName string, services []*Service) *Error
- func (c *Config) UpdateServiceServer(routeName string, serviceName string, serverName string, server *Server) *Error
- type Error
- type Filter
- type Frontend
- type Info
- type ProxyOptions
- type Quota
- type Route
- type Runtime
- func (r *Runtime) GetInfo() (Info, *Error)
- func (r *Runtime) GetJsonStats(statsType string) ([]Stats, error)
- func (r *Runtime) GetStats(statsType string) (map[string]map[string]string, error)
- func (r *Runtime) Reload(c *Config) error
- func (r *Runtime) Reset() *Error
- func (r *Runtime) SetPid(pidfile string) error
- func (r *Runtime) SetWeight(backend string, server string, weight int) (string, error)
- type Server
- type ServerDetail
- type Service
- type Stats
Constants ¶
const ( UserAgent string = "^[uU]ser[-.][aA]gent[ ]?([!])?=[ ]?([a-zA-Z0-9]+)$" Host string = "^[hH]ost[ ]?([!])?=[ ]?([a-zA-Z0-9.]+)$" CookieContains string = "^[cC]ookie (.*) [Cc]ontains (.*)$" HasCookie string = "^[Hh]as [Cc]ookie (.*)$" MissesCookie string = "^[Mm]isses [Cc]ookie (.*)$" HeaderContains string = "^[Hheader] (.*) [Cc]ontains (.*)$" HasHeader string = "^[Hh]as [Hh]eader (.*)$" MissesHeader string = "^[Mm]isses [Hh]eader (.*)$" )
const (
DEFAULT_WEIGHT = 100
)
const (
MAX_SOCKET_LENGTH = 103
)
const (
SEPARATOR = "::"
)
Variables ¶
This section is empty.
Functions ¶
func BackendName ¶
func FilterName ¶
func FrontendName ¶
func ServerName ¶
func ServiceName ¶
helper function to create a Backend or Frontend name based on a Route and Service
Types ¶
type Backend ¶
type Backend struct { Name string `json:"name" binding:"required"` Mode string `json:"mode" binding:"required"` Servers []*ServerDetail `json:"servers" binding:"required"` Options ProxyOptions `json:"options"` ProxyMode bool `json:"proxyMode" binding:"required"` }
Defines a single haproxy "backend".
type Config ¶
type Config struct { Frontends []*Frontend `json:"frontends" binding:"required"` Backends []*Backend `json:"backends" binding:"required"` Routes []Route `json:"routes" binding:"required"` PidFile string `json:"-"` SockFile string `json:"-"` Mutex *sync.RWMutex `json:"-"` TemplateFile string `json:"-"` ConfigFile string `json:"-"` JsonFile string `json:"-"` WorkingDir string `json:"-"` ErrorPagesDir string `json:"-"` }
Main configuration object for load balancers. This contains all variables and is passed to the templating engine.
func (*Config) AddFrontend ¶
adds a frontend
func (*Config) AddRouteServices ¶
func (*Config) AddServer ¶
func (c *Config) AddServer(backendName string, server *ServerDetail) *Error
adds a Server
func (*Config) AddServiceServer ¶
func (*Config) BackendExists ¶
helper function to check if a Backend exists
func (*Config) BackendUsed ¶
Helper function to check if a Backend is used by a Frontend as a default backend or a filter destination
func (*Config) BeginReadTrans ¶
func (c *Config) BeginReadTrans()
func (*Config) BeginWriteTrans ¶
func (c *Config) BeginWriteTrans()
the transactions methods are kept separate so we can chain an arbitrary set of operations on the Config object within one transaction. Alas, this burdons the developer with extra housekeeping but gives you more control over the flow of mutations and reads without risking deadlocks or duplicating locks and unlocks inside of methods.
func (*Config) DeleteBackend ¶
Deleting a backend is tricky. Frontends have a default backend. Removing that backend and then reloading
the configuration will crash Haproxy. This means some extra protection is put into this method to check if this backend is still used. If not, it can be deleted.
func (*Config) DeleteFilter ¶
delete a Filter from a frontend
func (*Config) DeleteFrontend ¶
deletes a frontend
func (*Config) DeleteRoute ¶
deletes a route, cascading down the structure and remove all underpinning frontends, backends and servers.
func (*Config) DeleteRouteService ¶
func (*Config) DeleteServer ¶
func (*Config) DeleteServiceServer ¶
func (*Config) EndReadTrans ¶
func (c *Config) EndReadTrans()
func (*Config) EndWriteTrans ¶
func (c *Config) EndWriteTrans()
func (*Config) FrontendExists ¶
helper function to check if a Frontend exists
func (*Config) GetBackend ¶
gets a backend
func (*Config) GetConfigFromDisk ¶
Load a config from disk
func (*Config) GetFilters ¶
get the filters from a frontend
func (*Config) GetFrontend ¶
gets a frontend
func (*Config) GetRouteService ¶
func (*Config) GetRouteServices ¶
func (*Config) GetServer ¶
func (c *Config) GetServer(backendName string, serverName string) (*ServerDetail, *Error)
func (*Config) GetServers ¶
func (c *Config) GetServers(backendName string) ([]*ServerDetail, *Error)
gets all servers of a specific backend
func (*Config) GetServiceServer ¶
func (*Config) GetServiceServers ¶
func (*Config) InitializeConfig ¶
func (c *Config) InitializeConfig()
func (*Config) RenderAndPersist ¶
func (*Config) RouteExists ¶
helper function to check if a Route exists
func (*Config) ServerExists ¶
helper function to check if a Server exists in a specific Service
func (*Config) ServiceExists ¶
helper function to check if a Service exists
func (*Config) UpdateConfig ¶
updates the whole config in one go
func (*Config) UpdateRoute ¶
just a convenience functions for a delete and a create
func (*Config) UpdateRouteService ¶
just a convenience functions for a delete and a create
func (*Config) UpdateRouteServices ¶
type Error ¶
custom error that allows us to define the HTTP return code that should be used in different error situations
type Frontend ¶
type Frontend struct { Name string `json:"name" binding:"required"` Mode string `json:"mode" binding:"required"` BindPort int `json:"bindPort"` BindIp string `json:"bindIp"` UnixSock string `json:"unixSock"` SockProtocol string `json:"sockProtocol"` Options ProxyOptions `json:"options"` DefaultBackend string `json:"defaultBackend" binding:"required"` Filters []*Filter `json:"filters,omitempty"` HttpQuota Quota `json:"httpQuota,omitempty"` TcpQuota Quota `json:"tcpQuota,omitempty"` }
Defines a single haproxy "frontend".
type Info ¶
type Info struct { Name string `json:"Name"` Version string `json:"Version"` Release_date string `json:"Release_date"` Nbproc string `json:"Nbproc"` Process_num string `json:"Process_num"` Pid string `json:"Pid"` Uptime string `json:"Uptime"` Uptime_sec string `json:"Uptime_sec"` Memmax_MB string `json:"Memmax_MB"` Ulimitn string `json:"Ulimit-n"` Maxsock string `json:"Maxsock"` Maxconn string `json:"Maxconn"` Hard_maxconn string `json:"Hard_maxconn"` CurrConns string `json:"CurrConns"` CumConns string `json:"CumConns"` CumReq string `json:"CumReq"` MaxSslConns string `json:"MaxSslConns"` CurrSslConns string `json:"CurrSslConns"` CumSslConns string `json:"CumSslConns"` Maxpipes string `json:"Maxpipes"` PipesUsed string `json:"PipesUsed"` PipesFree string `json:"PipesFree"` ConnRate string `json:"ConnRate"` ConnRateLimit string `json:"ConnRateLimit"` MaxConnRate string `json:"MaxConnRate"` SessRate string `json:"SessRate"` SessRateLimit string `json:"SessRateLimit"` MaxSessRate string `json:"MaxSessRate"` SslRate string `json:"SslRate"` SslRateLimit string `json:"SslRateLimit"` MaxSslRate string `json:"MaxSslRate"` SslFrontendKeyRate string `json:"SslFrontendKeyRate"` SslFrontendMaxKeyRate string `json:"SslFrontendMaxKeyRate"` SslFrontendSessionReuse_pct string `json:"SslFrontendSessionReuse_pct"` SslBackendKeyRate string `json:"SslBackendKeyRate"` SslBackendMaxKeyRate string `json:"SslBackendMaxKeyRate"` SslCacheLookups string `json:"SslCacheLookups"` SslCacheMisses string `json:"SslCacheMisses"` CompressBpsIn string `json:"CompressBpsIn"` CompressBpsOut string `json:"CompressBpsOut"` CompressBpsRateLim string `json:"CompressBpsRateLim"` ZlibMemUsage string `json:"ZlibMemUsage"` MaxZlibMemUsage string `json:"MaxZlibMemUsage"` Tasks string `json:"Tasks"` Run_queue string `json:"Run_queue"` Idle_pct string `json:"Idle_pct"` // contains filtered or unexported fields }
struct to hold the output from the /info endpoint
type ProxyOptions ¶
type ProxyOptions struct { AbortOnClose bool `json:"abortOnClose"` AllBackups bool `json:"allBackups"` CheckCache bool `json:"checkCache"` ForwardFor bool `json:"forwardFor"` HttpClose bool `json:"httpClose"` HttpCheck bool `json:"httpCheck"` SslHelloCheck bool `json:"sslHelloCheck"` TcpKeepAlive bool `json:"tcpKeepAlive"` TcpLog bool `json:"tcpLog"` TcpSmartAccept bool `json:"tcpSmartAccept"` TcpSmartConnect bool `json:"tcpSmartConnect"` }
type Route ¶
type Route struct { Name string `json:"name" binding:"required" valid:"routeName"` Port int `json:"port" binding:"required"` Protocol string `json:"protocol" binding:"required"` HttpQuota Quota `json:"httpQuota"` TcpQuota Quota `json:"tcpQuota"` Filters []*Filter `json:"filters"` Services []*Service `json:"services"` }
A Route is structured set of Haproxy frontends, backends and servers. The Route provides a convenient and higher level way of creating and managing this structure. You could create this structure by hand with separate API calls, but this is faster and easier in 9 out of 10 cases.
The structure of a route is as follows:
-> [srv a] -> sock -> [fe a: be a] -> [*srv] -> host:port / ->[fe (fltr)(qts) : be]- \ -> [srv b] -> sock -> [fe b: be b] -> [*srv] -> host:port fe = frontend be = backend srv = server fltr = filter qts = quotas
The above example has two services, a and b, but a route can have many services. The start of the route (the first frontend) has filters and quotas that influence the way traffic flows in a route, i.e. to which services the traffic goes.
All items in a route map to actual Haproxy types from the vamp-loadbalancer/haproxy package.
type Runtime ¶
type ServerDetail ¶
type ServerDetail struct { Name string `json:"name" binding:"required"` Host string `json:"host" binding:"required"` Port int `json:"port" binding:"required"` UnixSock string `json:"unixSock" valid:"socketPath"` Weight int `json:"weight" binding:"required"` MaxConn int `json:"maxconn"` Check bool `json:"check"` CheckInterval int `json:"checkInterval"` }
type Stats ¶
type Stats struct { Pxname string `json:"pxname"` Svname string `json:"svname"` Qcur string `json:"qcur"` Qmax string `json:"qmax"` Scur string `json:"scur"` Smax string `json:"smax"` Slim string `json:"slim"` Stot string `json:"stot"` Bin string `json:"bin"` Bout string `json:"bout"` Dreq string `json:"dreq"` Dresp string `json:"dresp"` Ereq string `json:"ereq"` Econ string `json:"econ"` Eresp string `json:"eresp"` Wretr string `json:"wretr"` Wredis string `json:"wredis"` Status string `json:"status"` Weight string `json:"weight"` Act string `json:"act"` Bck string `json:"bck"` Chkfail string `json:"chkfail"` Chkdown string `json:"chkdown"` Lastchg string `json:"lastchg"` Downtime string `json:"downtime"` Qlimit string `json:"qlimit"` Pid string `json:"pid"` Iid string `json:"iid"` Sid string `json:"sid"` Throttle string `json:"throttle"` Lbtot string `json:"lbtot"` Tracked string `json:"tracked"` Rate string `json:"rate"` Rate_lim string `json:"rate_lim"` Rate_max string `json:"rate_max"` Check_status string `json:"check_status"` Check_code string `json:"check_code"` Check_duration string `json:"check_duration"` Hrsp_1xx string `json:"hrsp_1xx"` Hrsp_2xx string `json:"hrsp_2xx"` Hrsp_3xx string `json:"hrsp_3xx"` Hrsp_4xx string `json:"hrsp_4xx"` Hrsp_5xx string `json:"hrsp_5xx"` Hrsp_other string `json:"hrsp_other"` Hanafail string `json:"hanafail"` Req_rate string `json:"req_rate"` Req_rate_max string `json:"req_rate_max"` Req_tot string `json:"req_tot"` Cli_abrt string `json:"cli_abrt"` Srv_abrt string `json:"srv_abrt"` Comp_in string `json:"comp_in"` Comp_out string `json:"comp_out"` Comp_byp string `json:"comp_byp"` Comp_rsp string `json:"comp_rsp"` Lastsess string `json:"lastsess"` Last_chk string `json:"last_chk"` Last_agt string `json:"last_agt"` Qtime string `json:"qtime"` Ctime string `json:"ctime"` Rtime string `json:"rtime"` Ttime string `json:"ttime"` // contains filtered or unexported fields }
Struct to hold the output from the /stats endpoint