Last active
April 5, 2018 11:32
-
-
Save WGH-/90bbfe656e63f6fa457db84f91384c41 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"io" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"time" | |
) | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
log.Printf("got request") | |
dur, err := time.ParseDuration(r.URL.Query().Get("t")) | |
if err != nil { | |
log.Print("failed to parse duration: ", err) | |
return | |
} | |
n, err := io.Copy(ioutil.Discard, r.Body) | |
if err != nil { | |
log.Print(err) | |
} | |
log.Printf("got %v bytes of data, sleeping for %v", n, dur) | |
time.Sleep(dur) | |
log.Print("sleep completed!") | |
}) | |
server := &http.Server{ | |
Addr: ":8080", | |
WriteTimeout: time.Second * 1, | |
} | |
log.Fatal(server.ListenAndServe()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment