Documentation
¶
Index ¶
- Constants
- func AuthenticateUser(on bool) middleware.Interface
- func ClientHTTPStatusAndError(err error) (int, error)
- func Error(w http.ResponseWriter, err error)
- func ErrorWithStatus(w http.ResponseWriter, err error, status int)
- func InstrumentedDefaultHTTPClient(instruments ...RoundTripperInstrumentFunc) *http.Client
- func InstrumentedHTTPClient(client *http.Client, instruments ...RoundTripperInstrumentFunc) *http.Client
- func K6Middleware() middleware.Interface
- func NewHTTPMetricMiddleware(mux *mux.Router, namespace string, reg prometheus.Registerer) (middleware.Interface, error)
- func RenderHTTPResponse(w http.ResponseWriter, v interface{}, t *template.Template, r *http.Request)
- func WriteHTMLResponse(w http.ResponseWriter, message string)
- func WriteJSONResponse(w http.ResponseWriter, v interface{})
- func WriteTextResponse(w http.ResponseWriter, message string)
- func WriteYAMLResponse(w http.ResponseWriter, v interface{})
- type Log
- type RoundTripperFunc
- type RoundTripperInstrumentFunc
Constants ¶
const ( ErrClientCanceled = "the request was cancelled by the client" ErrDeadlineExceeded = "" /* 159-byte string literal not displayed */ )
const StatusClientClosedRequest = 499
StatusClientClosedRequest is the status code for when a client request cancellation of an http request
Variables ¶
This section is empty.
Functions ¶
func AuthenticateUser ¶ added in v2.1.0
func AuthenticateUser(on bool) middleware.Interface
AuthenticateUser propagates the user ID from HTTP headers back to the request's context. If on is false, it will inject the default tenant ID.
func ClientHTTPStatusAndError ¶
ClientHTTPStatusAndError returns error and http status that is "safe" to return to client without exposing any implementation details.
func Error ¶
func Error(w http.ResponseWriter, err error)
Error write a go error with the correct status code.
func ErrorWithStatus ¶
func ErrorWithStatus(w http.ResponseWriter, err error, status int)
func InstrumentedDefaultHTTPClient ¶ added in v2.1.0
func InstrumentedDefaultHTTPClient(instruments ...RoundTripperInstrumentFunc) *http.Client
InstrumentedDefaultHTTPClient returns an http client configured with some default settings which is wrapped with a variety of instrumented RoundTrippers.
func InstrumentedHTTPClient ¶ added in v2.1.0
func InstrumentedHTTPClient(client *http.Client, instruments ...RoundTripperInstrumentFunc) *http.Client
InstrumentedHTTPClient adds the associated instrumentation middlewares to the provided http client.
func K6Middleware ¶
func K6Middleware() middleware.Interface
K6Middleware creates a middleware that extracts k6 load test labels from the request baggage and adds them as dynamic profiling labels.
func NewHTTPMetricMiddleware ¶ added in v2.1.0
func NewHTTPMetricMiddleware(mux *mux.Router, namespace string, reg prometheus.Registerer) (middleware.Interface, error)
NewHTTPMetricMiddleware creates a new middleware that automatically instruments HTTP requests from the given router.
func RenderHTTPResponse ¶ added in v2.1.0
func RenderHTTPResponse(w http.ResponseWriter, v interface{}, t *template.Template, r *http.Request)
RenderHTTPResponse either responds with JSON or a rendered HTML page using the passed in template by checking the Accepts header.
func WriteHTMLResponse ¶ added in v2.1.0
func WriteHTMLResponse(w http.ResponseWriter, message string)
WriteHTMLResponse sends message as text/html response with 200 status code.
func WriteJSONResponse ¶ added in v2.1.0
func WriteJSONResponse(w http.ResponseWriter, v interface{})
WriteJSONResponse writes some JSON as a HTTP response.
func WriteTextResponse ¶ added in v2.1.0
func WriteTextResponse(w http.ResponseWriter, message string)
WriteTextResponse sends message as text/plain response with 200 status code.
func WriteYAMLResponse ¶ added in v2.1.0
func WriteYAMLResponse(w http.ResponseWriter, v interface{})
WriteYAMLResponse writes some YAML as a HTTP response.
Types ¶
type Log ¶ added in v2.1.0
type Log struct {
Log log.Logger
LogRequestHeaders bool
LogRequestExcludeHeaders []string
LogRequestAtInfoLevel bool // LogRequestAtInfoLevel true -> log requests at info log level
SourceIPs *middleware.SourceIPExtractor
// contains filtered or unexported fields
}
Log middleware logs http requests
type RoundTripperFunc ¶ added in v2.1.0
type RoundTripperInstrumentFunc ¶ added in v2.1.0
type RoundTripperInstrumentFunc func(next http.RoundTripper) http.RoundTripper
func WithBaggageTransport ¶ added in v2.1.0
func WithBaggageTransport() RoundTripperInstrumentFunc
WithBaggageTransport will set the Baggage header on the request if there is any baggage in the context and it was not already set.
func WithTracingTransport ¶ added in v2.1.0
func WithTracingTransport() RoundTripperInstrumentFunc
WithTracingTransport wraps the given RoundTripper with a tracing instrumented one.