Skip to content

Instantly share code, notes, and snippets.

@bg451
Last active July 14, 2016 18:06
Show Gist options
  • Save bg451/7a1c4035662f82976e8d845e6ebac5a9 to your computer and use it in GitHub Desktop.
Save bg451/7a1c4035662f82976e8d845e6ebac5a9 to your computer and use it in GitHub Desktop.
// Acts as our index page
func indexHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<a href="/home"> Click here to start a request </a>`))
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Request started"))
go func() {
http.Get("http://localhost:8080/async")
}()
http.Get("http://localhost:8080/service")
time.Sleep(time.Duration(rand.Intn(200)) * time.Millisecond)
w.Write([]byte("Request done!"))
}
// Mocks a service endpoint that makes a DB call
func serviceHandler(w http.ResponseWriter, r *http.Request) {
// ...
http.Get("http://localhost:8080/db")
time.Sleep(time.Duration(rand.Intn(200)) * time.Millisecond)
// ...
}
// Mocks a DB call
func dbHandler(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Duration(rand.Intn(200)) * time.Millisecond)
// here would be the actual call to a DB.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment