Documentation ¶
Index ¶
- Constants
- Variables
- func BasicAuth(realm string, creds map[string]string) func(next http.Handler) http.Handler
- func GetReqID(ctx context.Context) string
- func NextRequestID() uint64
- func RequestID(next http.Handler) http.Handler
- func Throttle(limit int) func(http.Handler) http.Handler
- func ThrottleBacklog(limit, backlogLimit int, backlogTimeout time.Duration) func(http.Handler) http.Handler
- func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler
- func WrapperHandler(next http.Handler) http.Handler
- type ThrottleOpts
Constants ¶
const RequestIDKey ctxKeyRequestID = 0
RequestIDKey is the key that holds the unique request ID in a request context.
Variables ¶
var RequestIDHeader = "X-Request-Id"
RequestIDHeader is the name of the HTTP Header which contains the request id. Exported so that it can be changed by developers
Functions ¶
func BasicAuth ¶
BasicAuth implements a simple middleware handler for adding basic http auth to a route.
func GetReqID ¶
GetReqID returns a request ID from the given context if one is present. Returns the empty string if a request ID cannot be found.
func NextRequestID ¶
func NextRequestID() uint64
NextRequestID generates the next request ID in the sequence.
func RequestID ¶
RequestID is a middleware that injects a request ID into the context of each request. A request ID is a string of the form "host.example.com/random-0001", where "random" is a base62 random string that uniquely identifies this go process, and where the last number is an atomically incremented request counter.
func Throttle ¶
Throttle is a middleware that limits number of currently processed requests at a time across all users. Note: Throttle is not a rate-limiter per user, instead it just puts a ceiling on the number of currently in-flight requests being processed from the point from where the Throttle middleware is mounted.
func ThrottleBacklog ¶
func ThrottleBacklog(limit, backlogLimit int, backlogTimeout time.Duration) func(http.Handler) http.Handler
ThrottleBacklog is a middleware that limits number of currently processed requests at a time and provides a backlog for holding a finite number of pending requests.
func ThrottleWithOpts ¶
func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler
ThrottleWithOpts is a middleware that limits number of currently processed requests using passed ThrottleOpts.