tb

package
v0.0.0-...-2dd45e8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Attempts contextKey = iota
	Retry
)

Variables

This section is empty.

Functions

func GetAttemptsFromContext

func GetAttemptsFromContext(request *http.Request) int

func GetProxy

func GetProxy(s ServerPool, loadBalanceFunction LoadBalanceFunc, backendURL *url.URL) *httputil.ReverseProxy

func GetRetryFromContext

func GetRetryFromContext(request *http.Request) int

func SetAttemptsForContext

func SetAttemptsForContext(request *http.Request, attempts int) context.Context

func SetRetryForContext

func SetRetryForContext(request *http.Request, retries int) context.Context

Types

type Backend

type Backend struct {
	URL   *url.URL
	Alive bool

	ReverseProxy *httputil.ReverseProxy
	// contains filtered or unexported fields
}

func NewBackend

func NewBackend(backendURL *url.URL) *Backend

func (*Backend) CheckHealth

func (b *Backend) CheckHealth() (alive bool, err error)

func (*Backend) IsAlive

func (b *Backend) IsAlive() (alive bool)

func (*Backend) SetAlive

func (b *Backend) SetAlive(alive bool)

func (*Backend) SetProxyErrorHandler

func (b *Backend) SetProxyErrorHandler(errorHandler func(writer http.ResponseWriter, request *http.Request, err error))

type LoadBalanceFunc

type LoadBalanceFunc http.HandlerFunc

func GetLoadBalanceFunction

func GetLoadBalanceFunction(s ServerPool) LoadBalanceFunc

type RoundServerPool

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

func (*RoundServerPool) AddBackend

func (s *RoundServerPool) AddBackend(backend *Backend)

func (*RoundServerPool) ChechHealth

func (s *RoundServerPool) ChechHealth()

func (*RoundServerPool) GetNextPeer

func (s *RoundServerPool) GetNextPeer() *Backend

func (*RoundServerPool) MarkBackendStatus

func (s *RoundServerPool) MarkBackendStatus(backendUrl *url.URL, alive bool)

func (*RoundServerPool) NextIndex

func (s *RoundServerPool) NextIndex() int

type ServerPool

type ServerPool interface {
	NextIndex() int
	GetNextPeer() *Backend
	AddBackend(backend *Backend)
	MarkBackendStatus(backendUrl *url.URL, alive bool)
	ChechHealth()
}

type TbConfig

type TbConfig struct {
	Host     string   `yaml:"host"`
	Backends []string `yaml:"backends"`
}

func LoadConfig

func LoadConfig(configBytes []byte) (config *TbConfig, err error)

func LoadConfigFromFile

func LoadConfigFromFile(configPath string) (config *TbConfig, err error)

Jump to

Keyboard shortcuts

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