Skip to content

Instantly share code, notes, and snippets.

@vad
Created June 13, 2013 21:04
Show Gist options
  • Save vad/5777341 to your computer and use it in GitHub Desktop.
Save vad/5777341 to your computer and use it in GitHub Desktop.
Go waits
2013/06/13 22:56:59 Listening...
2013/06/13 22:57:03 Start request
2013/06/13 22:57:13 End request
2013/06/13 22:57:13 Start request
2013/06/13 22:57:23 End request
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", index)
log.Println("Listening...")
http.ListenAndServe(fmt.Sprintf(":%d", 9998), nil)
}
func index(w http.ResponseWriter, req *http.Request) {
log.Println("Start request")
resp, err := http.Get("http://localhost:9999/")
if err != nil {
w.Write([]byte("Connetion error"))
return
}
defer resp.Body.Close()
io.Copy(w, resp.Body)
log.Println("End request")
}
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func main() {
http.HandleFunc("/", index)
log.Println("Listening...")
http.ListenAndServe(fmt.Sprintf(":%d", 9999), nil)
}
func index(w http.ResponseWriter, req *http.Request) {
log.Println("Start request")
sleepTime := time.Duration(10) * time.Second
time.Sleep(sleepTime)
w.Write([]byte("Done\n"))
log.Println("End request")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment