diff options
author | Emile <hanemile@protonmail.com> | 2019-11-03 02:06:18 +0100 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-11-03 02:06:18 +0100 |
commit | 5a4c09b9ba2107f8f81fbae891808319ac676f4d (patch) | |
tree | bb8de1fe9beefdbf7307e2a045e284d054c7d8ed | |
parent | 22a31d99a51c124d03763a8631a0b1260bf4b7a6 (diff) |
return a random http code
-rw-r--r-- | main.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/main.go b/main.go new file mode 100644 index 0000000..8f8d5ed --- /dev/null +++ b/main.go @@ -0,0 +1,34 @@ +package main + +import ( + "flag" + "fmt" + "log" + "math/rand" + "net/http" + "time" + + "github.com/gorilla/mux" +) + +func main() { + + // register variables + var port = flag.Int("p", 8081, "port the http server listens on") + flag.Parse() + + // http foo + r := mux.NewRouter() + r.HandleFunc("/{.*}", indexHandler) + + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), r)) +} + +func indexHandler(w http.ResponseWriter, r *http.Request) { + + // seed using a truly random value + rand.Seed(time.Now().UnixNano()) + + // return a random value in range 100 to 511 + w.WriteHeader(rand.Intn(311) + 200) +} |