Guest User

Untitled

a guest
Dec 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. package main
  2.  
  3. import ("fmt"
  4. "net/http"
  5. //"log"
  6. "github.com/gorilla/mux"
  7. "time"
  8. //"net/http/fcgi"
  9. "io/ioutil"
  10. )
  11.  
  12. func timer(h http.HandlerFunc) (http.HandlerFunc){
  13. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  14. startTime := time.Now() //request time
  15. h.ServeHTTP(w, r) //original function called.
  16. duration := time.Now().Sub(startTime) //calculation of response time.
  17. fmt.Println(duration)
  18. })
  19. }
  20.  
  21. func main(){
  22. r := mux.NewRouter()
  23. r.HandleFunc("/", timer())
  24. http.Handle("/",r)
  25. http.ListenAndServe(":8080",r)
  26. }
Add Comment
Please, Sign In to add comment