daily pastebin goal
76%
SHARE
TWEET

Untitled

a guest Dec 14th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top