Documentation ¶
Index ¶
- func IsStatusError(statusCode int) bool
- func JsonErrMiddleware(next http.Handler, genericMessage bool) http.Handler
- func PromLogMiddleware(next http.Handler, histogram Histogram, l *zerolog.Logger) http.Handler
- func PromMiddleware(next http.Handler, histogram Histogram) http.Handler
- func ZerologMiddleware(next http.Handler, l *zerolog.Logger) http.Handler
- type Histogram
- type ReqThrottle
- type StatWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsStatusError ¶
func JsonErrMiddleware ¶
JsonErrMiddleware is a middleware mostly intended to handle http errors on a JSON api it will check if a handler wrote a non 2xx response code, intercept the response and transform it to a generic JSON error response.
the motivation is that we don't always control the error format of our responses and maybe also don't want to force json error responses always
if genericMessage is set to true, the error message will not printed; only the generic message related to the response code; this is intended for production environments to prevent leaking details about errors. TODO: this assumes that only 200 response codes contain usable body, e.g. not usable for rendering html
func PromLogMiddleware ¶
Types ¶
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
func NewHistogram ¶
func NewHistogram(prefix string, buckets []float64, registry prometheus.Registerer) Histogram
type ReqThrottle ¶
type StatWriter ¶
type StatWriter struct { http.ResponseWriter // contains filtered or unexported fields }
StatWriter is a wrapper to a httpResponse writer that allows to intercept and extract the status code that the upstream code has defined
func NewWriter ¶
func NewWriter(w http.ResponseWriter, teeBodyOnErr bool) *StatWriter
NewWriter will return a pointer to a response writer if teeBodyOnErr is set to true, and in case of a non 200 status code, the writer will not write the Response but instead into it's own buffer. this allows to modify the response before writing it to the output
func (*StatWriter) StatusCode ¶
func (r *StatWriter) StatusCode() int
func (*StatWriter) StatusCodeStr ¶
func (r *StatWriter) StatusCodeStr() string
func (*StatWriter) Write ¶
func (r *StatWriter) Write(b []byte) (int, error)
Write returns underlying Write result, while counting data size
func (*StatWriter) WriteHeader ¶
func (r *StatWriter) WriteHeader(code int)
WriteHeader writes the response status code and stores it internally