Skip to content

Instantly share code, notes, and snippets.

@nickpresta
Last active August 29, 2015 14:16
Show Gist options
  • Save nickpresta/f371330824e00eb30a8a to your computer and use it in GitHub Desktop.
Save nickpresta/f371330824e00eb30a8a to your computer and use it in GitHub Desktop.
Create a "delayed" JavaScript file
// Usage: Send GET request to /<seconds> to wait <seconds> seconds
package main
import (
"net/http"
"strconv"
"time"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
delay, err := strconv.Atoi(r.URL.Path[1:])
if err != nil {
delay = 3
}
time.Sleep(time.Duration(delay) * time.Second)
w.Header().Set("Content-type", "text/javascript")
w.Write([]byte(`console.log("loaded!");`))
})
panic(http.ListenAndServe(":10101", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment