Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Logger ¶
type Logger interface { Printf(format string, vals ...interface{}) ReqPrintf(reqID, format string, vals ...interface{}) }
Logger logs error messages for the caller where those errors don't require returning, i.e. the logging itself constitutes handling the error.
type Registry ¶
type Registry struct { // Services maps hostnames to one of the following: // // * IPs with optional healthcheck paths, OR // * A redirect to another hostname Services map[string]*backend // API restricts internal API access to a subnet, which should be an // private LAN. API struct{ Subnet string } }
Registry maps hosts to backends with other helpful info, such as healthchecks.
func NewRegistry ¶
NewRegistry for a given configuration file. This reports an error if any frontend host has no backends.
type ReverseProxy ¶
type ReverseProxy struct {
// contains filtered or unexported fields
}
ReverseProxy maps frontend hosts to backends. If HealthPath is set in the config.json file, ReverseProxy checks the health of backend servers periodically and automatically removes them from rotation until health checks pass.
func NewProxy ¶
func NewProxy(log Logger, reg *Registry) *ReverseProxy
NewProxy from a given Registry.
func (*ReverseProxy) CheckHealth ¶
func (r *ReverseProxy) CheckHealth() error
CheckHealth of backend servers in the registry concurrently, and update the registry so requests are only routed to healthy servers.
func (*ReverseProxy) RedirectHTTPHandler ¶
func (rp *ReverseProxy) RedirectHTTPHandler() (http.Handler, error)
RedirectHTTPHandler redirects http requests to use the API if the request originated from the whitelisted subnet. In all other GET and HEAD requests, this handler redirects to HTTPS. For POST, PUT, etc. this handler throws an error letting the client know to use HTTPS.
func (*ReverseProxy) ServeHTTP ¶
func (r *ReverseProxy) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*ReverseProxy) UpdateRegistry ¶
func (r *ReverseProxy) UpdateRegistry(reg *Registry)
UpdateRegistry for the reverse proxy with new frontends, backends, and health checks.