mapper

package
v0.0.0-...-dd64b79 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2016 License: MIT Imports: 5 Imported by: 2

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

func GroupByRequestIP(r *http.Request) string

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

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

type HandlerFactory func(key string) http.Handler

HandlerFactory is a function used to create a new http.Handler for the given group name.

type RequestGrouper

type RequestGrouper func(r *http.Request) string

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.

Jump to

Keyboard shortcuts

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