backend

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package backend implements a backend server and a server pool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoggerConfig

func LoggerConfig(prefix string)

func WriteBodyAndReturn

func WriteBodyAndReturn(rw http.ResponseWriter, resp *http.Response) ([]byte, error)

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

func NewBackend(url *url.URL, healthCheckTimeout time.Duration, maxRequests int32) *Backend

NewBackend creates a new Backend.

func NewBackendConfig

func NewBackendConfig(server config.ServerConfig) *Backend

NewBackendConfig creates a new Backend from config.ServerConfig.

func (*Backend) Alive

func (b *Backend) Alive() bool

Alive is used to check if the backend is alive.

func (*Backend) AssignRequest

func (b *Backend) AssignRequest() bool

AssignRequest returns true if backend's channel is not full. Apart from that, channel gets a new item.

func (*Backend) CheckIfAlive

func (b *Backend) CheckIfAlive() bool

CheckIfAlive checks if the backend is alive.

func (*Backend) Free

func (b *Backend) Free() bool

func (*Backend) HealthCheckTcpTimeout

func (b *Backend) HealthCheckTcpTimeout() time.Duration

HealthCheckTcpTimeout returns the timeout of the health check.

func (*Backend) Lock

func (b *Backend) Lock()

Lock are used to lock the backend.

func (*Backend) MaximalRequests

func (b *Backend) MaximalRequests() int

func (*Backend) SendRequestToBackend

func (b *Backend) SendRequestToBackend(req *http.Request) (*http.Response, error)

SendRequestToBackend returns error if there is an error on backend side.

func (*Backend) SetAlive

func (b *Backend) SetAlive(alive bool)

SetAlive sets the backend to alive or not alive.

func (*Backend) URL

func (b *Backend) URL() *url.URL

URL returns the URL of the backend.

func (*Backend) Unlock

func (b *Backend) Unlock()

Unlock are used to unlock the backend.

type ServerPool

type ServerPool struct {
	// contains filtered or unexported fields
}

ServerPool is a struct that contains all the configuration of the backend servers.

func NewServerPool

func NewServerPool() *ServerPool

NewServerPool creates a new ServerPool.

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) Lock

func (p *ServerPool) Lock()

Lock is used to lock the server pool.

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.

func (*ServerPool) Unlock

func (p *ServerPool) Unlock()

Unlock is used to unlock the server pool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL