responses

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ResponseTimeHeader = "X-Response-Time"

ResponseTimeHeader is the header name of response time. Change it if you use something different

Functions

func RequestDuration

func RequestDuration(reg prometheus.Registerer) func(http.Handler) http.Handler

RequestDuration adds a middleware to observe request durations and report to prometheus with the fully qualified name http_request_duration_seconds and labels for the status codes, method and the request path. Note that this handler only works if ResponseTime middleware is already Used. Also ensure it's used before any middleware that calls ResponseWriter.Write.

func ResponseTime

func ResponseTime(next http.Handler) http.Handler

ResponseTime adds a "X-Response-Time" header once the handler writes the header of the response. Ensure to Use this middleware before any middleware that Write.

func Send

func Send(w http.ResponseWriter, code int, data []byte)

Send writes a JSON response body and sets the content type of the response

Types

type TimedResponseWriter

type TimedResponseWriter interface {
	http.ResponseWriter
	Code() int
	Duration() time.Duration
}

TimedResponseWriter is a wrapper around the http.ResponseWriter allowing users to track the processing time of an handler.

Jump to

Keyboard shortcuts

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