Documentation ¶
Overview ¶
Package http implements a core suite of HTTP functions for use inside Moov. These packages are designed to be used in production to provide insight without an excessive performance tradeoff.
This package implements several opininated response functions (See Problem, InternalError) and stateless CORS handling under our load balancing setup. They may not work for you.
This package also implements a wrapper around http.ResponseWriter to log X-Request-ID, timing and the resulting status code.
Index ¶
- func AddCORSHandler(r *mux.Router)
- func GetRequestID(r *http.Request) string
- func GetSkipAndCount(r *http.Request) (skip int, count int, exists bool, err error)
- func GetUserID(r *http.Request) string
- func InternalError(w http.ResponseWriter, err error) string
- func LimitedSkipCount(r *http.Request, skipLimit, countLimit int) (skip int, count int, exists bool, err error)
- func Problem(w http.ResponseWriter, err error)
- func SetAccessControlAllowHeaders(w http.ResponseWriter, origin string)
- type Direction
- type OrderBy
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddCORSHandler ¶
AddCORSHandler captures Corss Origin Resource Sharing (CORS) requests by looking at all OPTIONS requests for the Origin header, parsing that and responding back with the other Access-Control-Allow-* headers.
Docs: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
func GetRequestID ¶ added in v0.10.0
GetRequestID returns the Moov header value for request IDs
func GetSkipAndCount ¶ added in v0.11.1
GetSkipAndCount returns the skip and count pagination values from the query parameters - skip is the number of records to pass over before starting a search (max math.MaxInt32) - count is the number of records to retrieve in the search (max 10,000) - exists indicates if skip or count was passed into the request URL
func InternalError ¶
func InternalError(w http.ResponseWriter, err error) string
InternalError writes err to w while also setting the HTTP status code, content-type and marshaling err as the response body.
Returned is the calling file and line number: server.go:33
func LimitedSkipCount ¶ added in v0.39.0
func LimitedSkipCount(r *http.Request, skipLimit, countLimit int) (skip int, count int, exists bool, err error)
LimitedSkipCount returns the skip and count pagination values from the request's query parameters See GetSkipAndCount for descriptions of each parameter
func Problem ¶
func Problem(w http.ResponseWriter, err error)
Problem writes err to w while also setting the HTTP status code, content-type and marshaling err as the response body.
func SetAccessControlAllowHeaders ¶
func SetAccessControlAllowHeaders(w http.ResponseWriter, origin string)
SetAccessControlAllowHeaders writes Access-Control-Allow-* headers to a response to allow for further CORS-allowed requests.
Types ¶
type ResponseWriter ¶
type ResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseWriter implements Go's standard library http.ResponseWriter to complete HTTP requests
func Wrap ¶
func Wrap(logger log.Logger, m metrics.Histogram, w http.ResponseWriter, r *http.Request) *ResponseWriter
Wrap returns a ResponseWriter usable by applications. No parts of the Request are inspected or ResponseWriter modified.
func (*ResponseWriter) WriteHeader ¶
func (w *ResponseWriter) WriteHeader(code int)
WriteHeader sends an HTTP response header with the provided status code, records response duration, and optionally records the HTTP metadata in a go-kit log.Logger