-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmocker.go
More file actions
36 lines (31 loc) · 817 Bytes
/
mocker.go
File metadata and controls
36 lines (31 loc) · 817 Bytes
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
35
36
package main
import (
"github.com/nickdirienzo/go-json-rest"
"math/rand"
"net/http"
"strconv"
)
type MockPin struct {
Lat float64
Long float64
Genre string
}
var genres = []string{"rock", "pop", "rap", "country", "dubstep", "electro house"}
func GenerateMockPin() MockPin {
lat := (rand.Float64() * 25) + 24.52
long := -1 * ((rand.Float64() * 57) + 66.95)
genre := genres[rand.Intn(len(genres))]
return MockPin{Lat: lat, Long: long, Genre: genre}
}
func (self *Api) GenerateMockPins(w *rest.ResponseWriter, r *rest.Request) {
n, err := strconv.Atoi(r.URL.Query().Get("n"))
if err != nil {
rest.Error(w, err.Error(), http.StatusBadRequest, "mockPins.get")
return
}
var pins []MockPin
for i := 0; i < n; i++ {
pins = append(pins, GenerateMockPin())
}
w.WriteJson(&pins, http.StatusOK)
}