The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/registry/apis/provisioning/timeout.go

21 lines
639 B

package provisioning
import (
"context"
"net/http"
"time"
)
// WithTimeout adds a timeout context to the request
func WithTimeout(h http.Handler, timeout time.Duration) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), timeout)
defer cancel()
h.ServeHTTP(w, r.WithContext(ctx))
})
}
// WithTimeoutFunc adds a timeout context to the request
func WithTimeoutFunc(f func(w http.ResponseWriter, r *http.Request), timeout time.Duration) func(w http.ResponseWriter, r *http.Request) {
return WithTimeout(http.HandlerFunc(f), timeout).ServeHTTP
}