Skip to content

Instantly share code, notes, and snippets.

@paulja
Created January 4, 2017 15:19
Show Gist options
  • Save paulja/fbe24b03dd2ec1a21077244a318f68a5 to your computer and use it in GitHub Desktop.
Save paulja/fbe24b03dd2ec1a21077244a318f68a5 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"net/http"
"strconv"
"time"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// tarpit
t := req.URL.Query().Get("t")
if t != "" {
d, _ := time.ParseDuration(t)
time.Sleep(d)
}
// status code
s := req.URL.Query().Get("s")
if s != "" {
c, _ := strconv.Atoi(s)
w.WriteHeader(c)
}
fmt.Fprintf(w, "Web Request: %s\n", req.URL.String())
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment