http

package
v0.0.0-...-5861b17 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// contains filtered or unexported methods
}

type HealthCheck

type HealthCheck func(ctx context.Context, endpoint string) error

HealthCheck provides a health check for a backend. The state passed is the current state of the backend. If state is Healthy but fails the check, this will cause the backend to be removed from service . If state is Sick and passes the check, the backend will be returned to service.

func HealthMultiplexer

func HealthMultiplexer(healthChecks ...HealthCheck) HealthCheck

HealthMultiplexer allows combining multiple HealthCheck(s) together.

func StatusCheck

func StatusCheck(urlPath string, healthyValues []string) (HealthCheck, error)

StatusCheck returns a HealthCheck that checks the status

type IPBackend

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

IPBackend provides a backend to our proxy that will use ip:port as the backend. This gives us static backends that isolate us from DNS changes or failures.

func NewIPBackend

func NewIPBackend(ip net.IP, port int32, urlPath string) (*IPBackend, error)

NewIPBackend is the constructor for IPBackend.

type LoadBalancer

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

LoadBalancer is an HTTP reverse proxy load balancer.

func New

func New() (*LoadBalancer, error)

New creates a new LoadBalancer instance.

func (*LoadBalancer) AddPool

func (l *LoadBalancer) AddPool(pattern string, pool Pool) error

AddPool adds a pool of backends that serve the serveURL listed here. If a pattern is added more than once, this will panic.

func (*LoadBalancer) GetPool

func (l *LoadBalancer) GetPool(pattern string) (Pool, error)

GetPool returns a pool by its pattern.

func (*LoadBalancer) PoolHealth

func (l *LoadBalancer) PoolHealth(ctx context.Context, req *pb.PoolHealthReq) (*pb.PoolHealth, error)

PoolHealth returns the health of a pool as defined in the req.

func (*LoadBalancer) RemovePool

func (l *LoadBalancer) RemovePool(pattern string) error

RemovePool removes a pool of backends that serve a pattern. If the pattern does not exist, the error is still nil.

func (*LoadBalancer) Serve

func (l *LoadBalancer) Serve(lis net.Listener) error

Serve will serve HTTP traffic(non-TLS) on lis.

func (*LoadBalancer) ServeTLS

func (l *LoadBalancer) ServeTLS(lis net.Listener, certFile, keyFile string) error

ServeTLS will serve HTTPS traffic on lis. See http.Server.ServeTLS for more documentation.

type P2C

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

P2C implements Pool using the Power of 2 choice selection method.

func NewP2C

func NewP2C(hc HealthCheck, interval time.Duration) (*P2C, error)

NewP2C creates a new P2C instance. hc is the health check to perform on the backend to make sure its healthy and interval is how often to do the health check.

func (*P2C) Add

func (s *P2C) Add(ctx context.Context, b Backend) error

Add implements Pool.Add().

func (*P2C) Close

func (s *P2C) Close() error

Close implements Pool.Close().

func (*P2C) Health

func (s *P2C) Health(ctx context.Context, req *pb.PoolHealthReq) (*pb.PoolHealth, error)

Health implements Pool.Health().

func (*P2C) Remove

func (s *P2C) Remove(ctx context.Context, b Backend) error

Remove implements Pool.Remove().

func (*P2C) ServeHTTP

func (s *P2C) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements Pool.ServeHTTP().

type Pool

type Pool interface {
	// Add adds a new Backend to the pool. The Backend must be healthy.
	Add(ctx context.Context, b Backend) error
	// Remove removes a backend from the loadbalancer.
	Remove(ctx context.Context, b Backend) error
	// Health returns the health of a pool.
	Health(ctx context.Context, req *pb.PoolHealthReq) (*pb.PoolHealth, error)
	// Close closes the pool. It should not be used after this.
	Close() error
	// ServeHTTP implements http.Handler.
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Pool represents a set of backends that serve a URL.

Jump to

Keyboard shortcuts

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