Documentation ¶
Overview ¶
Package backend implements a backend server and a server pool.
Index ¶
- func LoggerConfig(prefix string)
- func WriteBodyAndReturn(rw http.ResponseWriter, resp *http.Response) ([]byte, error)
- type Backend
- func (b *Backend) Alive() bool
- func (b *Backend) AssignRequest() bool
- func (b *Backend) CheckIfAlive() bool
- func (b *Backend) Free() bool
- func (b *Backend) HealthCheckTcpTimeout() time.Duration
- func (b *Backend) Lock()
- func (b *Backend) MaximalRequests() int
- func (b *Backend) SendRequestToBackend(req *http.Request) (*http.Response, error)
- func (b *Backend) SetAlive(alive bool)
- func (b *Backend) URL() *url.URL
- func (b *Backend) Unlock()
- type ServerPool
- func (p *ServerPool) AddServer(b *Backend)
- func (p *ServerPool) ConfigureServerPool(servers []config.ServerConfig)
- func (p *ServerPool) Current() int32
- func (p *ServerPool) DecrementCurrent()
- func (p *ServerPool) FindServerByUrl(url string) *Backend
- func (p *ServerPool) GetCurrentServer() *Backend
- func (p *ServerPool) GetNextPeer() (*Backend, error)
- func (p *ServerPool) IncrementCurrent()
- func (p *ServerPool) Lock()
- func (p *ServerPool) RemoveServerByUrl(url string) error
- func (p *ServerPool) Servers() []*Backend
- func (p *ServerPool) ServersURLs() []string
- func (p *ServerPool) Unlock()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoggerConfig ¶
func LoggerConfig(prefix string)
func WriteBodyAndReturn ¶
WriteBodyAndReturn writes response to the client and returns the response body.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is a struct that contains all the configuration of the backend server.
func NewBackend ¶
NewBackend creates a new Backend.
func NewBackendConfig ¶
func NewBackendConfig(server config.ServerConfig) *Backend
NewBackendConfig creates a new Backend from config.ServerConfig.
func (*Backend) AssignRequest ¶
AssignRequest returns true if backend's channel is not full. Apart from that, channel gets a new item.
func (*Backend) CheckIfAlive ¶
CheckIfAlive checks if the backend is alive.
func (*Backend) HealthCheckTcpTimeout ¶
HealthCheckTcpTimeout returns the timeout of the health check.
func (*Backend) MaximalRequests ¶
func (*Backend) SendRequestToBackend ¶
SendRequestToBackend returns error if there is an error on backend side.
type ServerPool ¶
type ServerPool struct {
// contains filtered or unexported fields
}
ServerPool is a struct that contains all the configuration of the backend servers.
func (*ServerPool) AddServer ¶
func (p *ServerPool) AddServer(b *Backend)
AddServer adds a new server to the server pool.
func (*ServerPool) ConfigureServerPool ¶
func (p *ServerPool) ConfigureServerPool(servers []config.ServerConfig)
ConfigureServerPool creates a new ServerPool from config.ServerConfig.
func (*ServerPool) Current ¶
func (p *ServerPool) Current() int32
Current returns the index of the current server.
func (*ServerPool) DecrementCurrent ¶
func (p *ServerPool) DecrementCurrent()
DecrementCurrent decrements the current server index.
func (*ServerPool) FindServerByUrl ¶
func (p *ServerPool) FindServerByUrl(url string) *Backend
FindServerByUrl finds a server by its URL.
func (*ServerPool) GetCurrentServer ¶
func (p *ServerPool) GetCurrentServer() *Backend
GetCurrentServer returns the current server.
func (*ServerPool) GetNextPeer ¶
func (p *ServerPool) GetNextPeer() (*Backend, error)
GetNextPeer returns the next server in the server pool.
func (*ServerPool) IncrementCurrent ¶
func (p *ServerPool) IncrementCurrent()
IncrementCurrent increments the current server index.
func (*ServerPool) RemoveServerByUrl ¶
func (p *ServerPool) RemoveServerByUrl(url string) error
RemoveServerByUrl removes a server by its URL.
func (*ServerPool) Servers ¶
func (p *ServerPool) Servers() []*Backend
Servers returns the servers of the server pool.
func (*ServerPool) ServersURLs ¶
func (p *ServerPool) ServersURLs() []string
ServersURLs returns the URLs of the servers in the server pool.