Documentation ¶
Index ¶
- Variables
- func GetRequest(ctx netContext.Context) (*http.Request, error)
- func GetRequestID(ctx netContext.Context) string
- func GetRequestLogger(ctx netContext.Context) context.Logger
- func GetResponseLogger(ctx netContext.Context) context.Logger
- func GetResponseWriter(ctx netContext.Context) (http.ResponseWriter, error)
- func RemoteAddr(r *http.Request) string
- func RemoteIP(r *http.Request) string
- func WithRequest(ctx netContext.Context, r *http.Request) netContext.Context
- func WithResponseWriter(ctx netContext.Context, w http.ResponseWriter) (netContext.Context, http.ResponseWriter)
- func WithVars(ctx netContext.Context, r *http.Request) netContext.Context
Constants ¶
This section is empty.
Variables ¶
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 ¶
RemoteAddr extracts the remote address 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 ¶
func WithResponseWriter(ctx netContext.Context, w http.ResponseWriter) (netContext.Context, http.ResponseWriter)
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.