Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import ("fmt"
- "net/http"
- //"log"
- "github.com/gorilla/mux"
- "time"
- //"net/http/fcgi"
- "io/ioutil"
- )
- func timer(h http.HandlerFunc) (http.HandlerFunc){
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- startTime := time.Now() //request time
- h.ServeHTTP(w, r) //original function called.
- duration := time.Now().Sub(startTime) //calculation of response time.
- fmt.Println(duration)
- })
- }
- func main(){
- r := mux.NewRouter()
- r.HandleFunc("/", timer())
- http.Handle("/",r)
- http.ListenAndServe(":8080",r)
- }
Add Comment
Please, Sign In to add comment