Advertisement
Guest User

Untitled

a guest
Jan 8th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "net/http"
  5.     "time"
  6.     "fmt"
  7. )
  8.  
  9. func main() {
  10.     http.HandleFunc("/hello", hello)
  11.     http.ListenAndServe(":8080", nil)
  12. }
  13.  
  14. func hello(w http.ResponseWriter, r *http.Request) {
  15.     s := time.Now()
  16.     fmt.Println("Start: ", s)
  17.  
  18.     time.Sleep(15 * time.Second)
  19.     w.Write([]byte("hello!"))
  20.  
  21.     e := time.Now()
  22.     fmt.Println("Stop: ", e)
  23. }
  24.  
  25. /* Output for the request run at same time
  26. Start:  2016-01-08 18:20:23.205378808 +0100 CET
  27. Stop:  2016-01-08 18:20:38.208704065 +0100 CET
  28. Start:  2016-01-08 18:20:38.210874469 +0100 CET
  29. Stop:  2016-01-08 18:20:53.21145758 +0100 CET
  30. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement