Created
June 13, 2013 21:04
-
-
Save vad/5777341 to your computer and use it in GitHub Desktop.
Go waits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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