pool

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HTTP Status codes
	StatusMovedPermanently  = http.StatusMovedPermanently
	StatusFound             = http.StatusFound
	StatusSeeOther          = http.StatusSeeOther
	StatusTemporaryRedirect = http.StatusTemporaryRedirect
	StatusPermanentRedirect = http.StatusPermanentRedirect

	// Header keys
	HeaderServer         = "Server"
	HeaderXPoweredBy     = "X-Powered-By"
	HeaderXProxyBy       = "X-Proxy-By"
	HeaderLocation       = "Location"
	HeaderXForwardedFor  = "X-Forwarded-For"
	HeaderXForwardedHost = "X-Forwarded-Host"
	HeaderHost           = "Host"

	DefaultScheme     = "http"
	DefaultProxyLabel = "terraster"
)
View Source
const (
	RetryKey contextKey = iota
)

Variables

This section is empty.

Functions

func GetRetryFromContext

func GetRetryFromContext(r *http.Request) int

helper function for retry context

Types

type Backend

type Backend struct {
	URL             *url.URL
	Host            string
	Alive           bool
	Weight          int
	CurrentWeight   int
	Proxy           *URLRewriteProxy
	ConnectionCount int32
	MaxConnections  int32
	// contains filtered or unexported fields
}

func (*Backend) DecrementConnections

func (b *Backend) DecrementConnections()

func (*Backend) GetConnectionCount

func (b *Backend) GetConnectionCount() int

func (*Backend) GetCurrentWeight

func (b *Backend) GetCurrentWeight() int

func (*Backend) GetURL

func (b *Backend) GetURL() string

func (*Backend) GetWeight

func (b *Backend) GetWeight() int

func (*Backend) IncrementConnections

func (b *Backend) IncrementConnections() bool

func (*Backend) IsAlive

func (b *Backend) IsAlive() bool

func (*Backend) SetCurrentWeight

func (b *Backend) SetCurrentWeight(weight int)

type BufferPool

type BufferPool struct {
	sync.Pool
}

func NewBufferPool

func NewBufferPool() *BufferPool

func (*BufferPool) Get

func (b *BufferPool) Get() []byte

func (*BufferPool) Put

func (b *BufferPool) Put(buf []byte)

type ConnectionPool

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

func NewConnectionPool

func NewConnectionPool(maxIdle, maxOpen int, idleTimeout time.Duration) *ConnectionPool

func (*ConnectionPool) Get

func (p *ConnectionPool) Get() *http.Client

func (*ConnectionPool) Put

func (p *ConnectionPool) Put(client *http.Client)

type PoolConfig

type PoolConfig struct {
	Algorithm string `json:"algorithm"`
	MaxConns  int32  `json:"max_connections"`
}

type ProxyError

type ProxyError struct {
	Op  string
	Err error
}

func (*ProxyError) Error

func (e *ProxyError) Error() string

type ProxyOption

type ProxyOption func(*URLRewriteProxy)

func WithLogger

func WithLogger(logger *log.Logger) ProxyOption

func WithURLRewriter

func WithURLRewriter(config RouteConfig, backendURL *url.URL) ProxyOption

type RewriteConfig

type RewriteConfig struct {
	ProxyPath  string
	RewriteURL string
	Redirect   string
}

type RouteConfig

type RouteConfig struct {
	Path          string // path is proxy path (upstream) (optional)
	RewriteURL    string // rewriteURL is the URL to rewrite to (downstream) (optional)
	Redirect      string // URL to redirect to (optional)
	SkipTLSVerify bool   // skipTLSVerify skips TLS verification (optional)
}

type ServerPool

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

func NewServerPool

func NewServerPool() *ServerPool

func (*ServerPool) AddBackend

func (s *ServerPool) AddBackend(cfg config.BackendConfig, rc RouteConfig) error

func (*ServerPool) GetAlgorithm

func (s *ServerPool) GetAlgorithm() algorithm.Algorithm

func (*ServerPool) GetBackendByURL

func (s *ServerPool) GetBackendByURL(url string) *Backend

func (*ServerPool) GetBackends

func (s *ServerPool) GetBackends() []*algorithm.Server

func (*ServerPool) GetConfig

func (s *ServerPool) GetConfig() PoolConfig

func (*ServerPool) GetCurrentIndex

func (s *ServerPool) GetCurrentIndex() uint64

func (*ServerPool) GetMaxConnections

func (s *ServerPool) GetMaxConnections() int32

func (*ServerPool) GetNextPeer

func (s *ServerPool) GetNextPeer() *Backend

func (*ServerPool) GetNextProxy

func (s *ServerPool) GetNextProxy(r *http.Request) *URLRewriteProxy

func (*ServerPool) MarkBackendStatus

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

func (*ServerPool) RemoveBackend

func (s *ServerPool) RemoveBackend(backendURL string) error

func (*ServerPool) SetAlgorithm

func (s *ServerPool) SetAlgorithm(algorithm algorithm.Algorithm) error

func (*ServerPool) SetCurrentIndex

func (s *ServerPool) SetCurrentIndex(idx uint64)

func (*ServerPool) SetMaxConnections

func (s *ServerPool) SetMaxConnections(maxConns int32) error

func (*ServerPool) UpdateBackends

func (s *ServerPool) UpdateBackends(configs []config.BackendConfig) error

Add method to update backends from config

func (*ServerPool) UpdateConfig

func (s *ServerPool) UpdateConfig(update PoolConfig)

type Transport

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

func NewTransport

func NewTransport(transport http.RoundTripper, skipTLSVerify bool) *Transport

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

type URLRewriteProxy

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

func NewReverseProxy

func NewReverseProxy(
	target *url.URL,
	config RouteConfig,
	px *httputil.ReverseProxy,
	opts ...ProxyOption,
) *URLRewriteProxy

func (*URLRewriteProxy) ServeHTTP

func (p *URLRewriteProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

type URLRewriter

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

func NewURLRewriter

func NewURLRewriter(config RewriteConfig, backendURL *url.URL) *URLRewriter

Jump to

Keyboard shortcuts

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