Skip to content

Instantly share code, notes, and snippets.

@CAFxX
Created April 14, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CAFxX/14f5192051504b893d4087d084dff514 to your computer and use it in GitHub Desktop.
Save CAFxX/14f5192051504b893d4087d084dff514 to your computer and use it in GitHub Desktop.
server_timing.go
func serverTiming(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
w.Header().Add("Trailer", "Server-Timing")
defer func() {
dur := time.Since(start).Seconds()
w.Header().Set("Server-Timing", fmt.Sprintf("total;dur=%f", dur))
}()
next.ServeHTTP(w, r)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment