Documentation
¶
Overview ¶
Package reverseproxy provides a reverse proxy implementation in Go. It allows you to create a reverse proxy server that forwards HTTP requests to a remote server. The package includes features like response modification, error handling, and request rewriting.
Index ¶
- type HttpErrorHandler
- type ResponseModifier
- type ResponseModifierMap
- type ReverseProxyMux
- func (p *ReverseProxyMux) GetLoad() int32
- func (pm *ReverseProxyMux) HandlePath(route Route) *ReverseProxyMux
- func (p *ReverseProxyMux) IsAvailable() bool
- func (pm *ReverseProxyMux) PassAnyPath(methods string) *ReverseProxyMux
- func (pm *ReverseProxyMux) PassAnyPathUnder(methods string, paths ...string) *ReverseProxyMux
- func (pm *ReverseProxyMux) PassPath(methods, path string) *ReverseProxyMux
- func (pm *ReverseProxyMux) PassPaths(methods string, paths ...string) *ReverseProxyMux
- func (pm *ReverseProxyMux) RewritePath(methods, sourcePath, targetPath string) *ReverseProxyMux
- func (pm *ReverseProxyMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (p *ReverseProxyMux) SetHealthCheckFunc(check func(addr *url.URL) bool, period time.Duration)
- type Route
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HttpErrorHandler ¶
type HttpErrorHandler func(http.ResponseWriter, *http.Request, error)
HttpErrorHandler is a function that handles errors occurring in HTTP request handlers.
type ResponseModifier ¶
ResponseModifier is a function that modifies the HTTP response.
type ResponseModifierMap ¶
type ResponseModifierMap map[string]map[string]ResponseModifier
ResponseModifierMap is a map of [method][path]ResponseModifier.
type ReverseProxyMux ¶
type ReverseProxyMux struct { Transport http.RoundTripper RequestHeader http.Header ModifyResponse ResponseModifier ErrorHandler HttpErrorHandler NotFoundHandler http.Handler MethodNotAllowedHandler http.Handler // contains filtered or unexported fields }
ReverseProxyMux is a reverse proxy with a request path multiplexer.
func New ¶
func New(remote string) (*ReverseProxyMux, error)
New creates a new ReverseProxyMux with the specified remote URL.
func (*ReverseProxyMux) GetLoad ¶
func (p *ReverseProxyMux) GetLoad() int32
GetLoad returns the number of requests being served by the proxy at the moment
func (*ReverseProxyMux) HandlePath ¶
func (pm *ReverseProxyMux) HandlePath(route Route) *ReverseProxyMux
HandlePath registers a route.
func (*ReverseProxyMux) IsAvailable ¶
func (p *ReverseProxyMux) IsAvailable() bool
IsAvailable returns whether the proxy origin was successfully connected at the last check time.
func (*ReverseProxyMux) PassAnyPath ¶
func (pm *ReverseProxyMux) PassAnyPath(methods string) *ReverseProxyMux
PassAnyPath registers all possible paths with the specified HTTP methods.
func (*ReverseProxyMux) PassAnyPathUnder ¶
func (pm *ReverseProxyMux) PassAnyPathUnder(methods string, paths ...string) *ReverseProxyMux
PassAnyPathUnder registers all possible paths under the specified parent paths with the specified HTTP methods.
func (*ReverseProxyMux) PassPath ¶
func (pm *ReverseProxyMux) PassPath(methods, path string) *ReverseProxyMux
PassPath registers a path with the specified HTTP methods.
func (*ReverseProxyMux) PassPaths ¶
func (pm *ReverseProxyMux) PassPaths(methods string, paths ...string) *ReverseProxyMux
PassPaths registers multiple paths with the specified HTTP methods.
func (*ReverseProxyMux) RewritePath ¶
func (pm *ReverseProxyMux) RewritePath(methods, sourcePath, targetPath string) *ReverseProxyMux
RewritePath registers a route with the specified HTTP methods and source path, and rewrites the request path to the target path.
func (*ReverseProxyMux) ServeHTTP ¶
func (pm *ReverseProxyMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles the HTTP request.
func (*ReverseProxyMux) SetHealthCheckFunc ¶
SetHealthCheckFunc sets the passed check func as the algorithm of checking the origin availability
type Route ¶
type Route struct { Method []string Path string RewritePath string RequestHeader http.Header ModifyResponse ResponseModifier }
func (Route) SetModifyResponse ¶
func (r Route) SetModifyResponse(modifier ResponseModifier) Route