Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sleep server, connects, but takes ages to respond
package main
import(
"fmt"
"net/http"
"log"
"time"
"flag"
)
func main() {
var timeout = flag.Int("timeout", 60, "how many seconds to sleep")
flag.Parse()
sleepDuration := time.Duration(*timeout) * time.Second
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
log.Printf("connected, will sleep for %s seconds\n", sleepDuration)
time.Sleep(sleepDuration)
fmt.Fprint(w, "Hello, i am very very slow")
log.Printf("responded\n")
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.