context

package
v0.0.0-...-798504f Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRequestContext        = errors.New("no http request in context")
	ErrNoResponseWriterContext = errors.New("no http response in context")
)

Common errors used with this package.

Functions

func GetRequest

func GetRequest(ctx netContext.Context) (*http.Request, error)

GetRequest returns the http request in the given context. Returns ErrNoRequestContext if the context does not have an http request associated with it.

func GetRequestID

func GetRequestID(ctx netContext.Context) string

GetRequestID attempts to resolve the current request id, if possible. An error is return if it is not available on the context.

func GetRequestLogger

func GetRequestLogger(ctx netContext.Context) context.Logger

GetRequestLogger returns a logger that contains fields from the request in the current context. If the request is not available in the context, no fields will display. Request loggers can safely be pushed onto the context.

func GetResponseLogger

func GetResponseLogger(ctx netContext.Context) context.Logger

GetResponseLogger reads the current response stats and builds a logger. Because the values are read at call time, pushing a logger returned from this function on the context will lead to missing or invalid data. Only call this at the end of a request, after the response has been written.

func GetResponseWriter

func GetResponseWriter(ctx netContext.Context) (http.ResponseWriter, error)

GetResponseWriter returns the http.ResponseWriter from the provided context. If not present, ErrNoResponseWriterContext is returned. The returned instance provides instrumentation in the context.

func RemoteAddr

func RemoteAddr(r *http.Request) string

RemoteAddr extracts the remote address of the request, taking into account proxy headers.

func RemoteIP

func RemoteIP(r *http.Request) string

RemoteIP extracts the remote IP of the request, taking into account proxy headers.

func WithRequest

func WithRequest(ctx netContext.Context, r *http.Request) netContext.Context

WithRequest places the request on the context. The context of the request is assigned a unique id, available at "http.request.id". The request itself is available at "http.request". Other common attributes are available under the prefix "http.request.". If a request is already present on the context, this method will panic.

func WithResponseWriter

WithResponseWriter returns a new context and response writer that makes interesting response statistics available within the context.

func WithVars

func WithVars(ctx netContext.Context, r *http.Request) netContext.Context

WithVars extracts gorilla/mux vars and makes them available on the returned context. Variables are available at keys with the prefix "vars.". For example, if looking for the variable "name", it can be accessed as "vars.name". Implementations that are accessing values need not know that the underlying context is implemented with gorilla/mux vars.

Types

This section is empty.

Jump to

Keyboard shortcuts

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