-
Notifications
You must be signed in to change notification settings - Fork 6
/
mockup.go
47 lines (39 loc) · 977 Bytes
/
mockup.go
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
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"log"
)
var mockupResponse string
type Location struct {
Lat float64 `json:"latitude"`
Long float64 `json:"longitude"`
Turn int64 `json:"turn"`
}
type MockDataType struct {
Name string `json:"algorithm"`
BatteryStatus float64 `json:"batteryStatus"`
Locations []Location `json:"route"`
Time float64 `json:"time"`
Distance float64 `json:"distance"`
}
func init() {
fileContent, _ := ioutil.ReadFile("mockup-response.json")
var data MockDataType
err := json.Unmarshal(fileContent, &data)
if err != nil {
log.Fatal(err)
}
mockupResponse = string(fileContent)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
fmt.Fprintf(w, mockupResponse)
}
func main() {
fmt.Println("Listening on http://localhost:6833. Ctrl+C to exit")
http.HandleFunc("/", handler)
http.ListenAndServe(":6833", nil)
}