blob: 8f8d5ed79a6f814763e65b41ebbcab7eac675f32 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)
}
|