File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ func main() {
28
28
http .HandleFunc ("/images/" , staticHandler .ServeHTTP )
29
29
http .HandleFunc ("/api/rank.json" , apiHandler )
30
30
http .HandleFunc ("/api/multiple.json" , multiHandler )
31
+ http .HandleFunc ("/api/random.json" , randomHandler )
31
32
32
33
err := http .ListenAndServe (listenAddress + ":" + strconv .Itoa (listenPort ), nil )
33
34
if err != nil {
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "net/http"
4
+
5
+ type RandomResponse struct {
6
+ Success bool `json:"success"`
7
+ Message string `json:"message"`
8
+ Domain string `json:"domain"`
9
+ Notice string `json:"notice"`
10
+ }
11
+
12
+ func randomHandler (w http.ResponseWriter , r * http.Request ) {
13
+
14
+ retVal := RandomResponse {}
15
+ retVal .Notice = "Free for light, non-commericial use. For heavy or commercial use, please contact us."
16
+
17
+ // pick a random key from the rankings map: since go tries to be non-deterministic, we'll just pick the first one
18
+ for k := range rankings {
19
+ retVal .Domain = k
20
+ break
21
+ }
22
+
23
+ retVal .Success = true
24
+ retVal .Message = "OK"
25
+
26
+ handleJson (w , r , retVal )
27
+ }
You can’t perform that action at this time.
0 commit comments