Documentation ¶
Overview ¶
Package mapper provides HTTP request mapping based on arbitrary criteria, including the raw HTTP request details. This enables servicing requests with specialized handlers which are potentially created just in time to handle the request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GroupByRequestIP ¶
GroupByRequestIP is used to make a best-effort attempt at determining the original requestor's IP address. The order of precedence is:
1. X-Forwarded-For header value. 2. IP address derived from the RemoteAddr of the request. 3. RemoteAddr raw value of the request (auto-set by the HTTP server).
func New ¶
func New(g RequestGrouper, f HandlerFactory, r time.Duration) http.Handler
New creates a new grouping HTTP handler. Requests are grouped by g, each group's http handler is created by f, and the group handler instance expires after duration r. After expiration, subsequent requests will create a replacement handler using the factory. The expiration timer for a group is reset at the beginning of each request. A zero value for r means no expiration, and is only recommended when grouping on commonly-seen request parameter values (request path, headers, etc). A good rule of thumb is to set the reap time to 2x the estimated max request duration.
Types ¶
type HandlerFactory ¶
HandlerFactory is a function used to create a new http.Handler for the given group name.
type RequestGrouper ¶
RequestGrouper is a function used to examine an HTTP request and return a key, which is used to group the request to a specific handler.