proxy

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	XRealIP       = http.CanonicalHeaderKey("X-Real-IP")
	XProxy        = http.CanonicalHeaderKey("X-Proxy")
	XForwardedFor = http.CanonicalHeaderKey("X-Forwarded-For")
)
View Source
var ConnectionTimeout = 3 * time.Second

ConnectionTimeout refers to connection timeout for health check

View Source
var (
	ReverseProxy = "Balancer-Reverse-Proxy"
)

Functions

func GetHost

func GetHost(url *url.URL) string

GetHost get the hostname, looks like IP:Port

func GetIP

func GetIP(r *http.Request) string

GetIP get client IP

func IsBackendAlive

func IsBackendAlive(host string) bool

IsBackendAlive attempt to establish a tcp connection to check whether the site is alive

Types

type HTTPProxy

type HTTPProxy struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

HTTPProxy refers to a reverse proxy in the balancer

func NewHTTPProxy

func NewHTTPProxy(targetHosts []string, algorithm string) (*HTTPProxy, error)

NewHTTPProxy create new reverse proxy with url and balancer algorithm

func (*HTTPProxy) HealthCheck

func (h *HTTPProxy) HealthCheck(interval uint)

HealthCheck enable a health check goroutine for each agent

func (*HTTPProxy) ReadAlive

func (h *HTTPProxy) ReadAlive(url string) bool

ReadAlive reads the alive status of the site

func (*HTTPProxy) ServeHTTP

func (h *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements a proxy to the http server

func (*HTTPProxy) SetAlive

func (h *HTTPProxy) SetAlive(url string, alive bool)

SetAlive sets the alive status to the site

Jump to

Keyboard shortcuts

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