Created
April 14, 2021 14:59
-
-
Save CAFxX/14f5192051504b893d4087d084dff514 to your computer and use it in GitHub Desktop.
server_timing.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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