-
Notifications
You must be signed in to change notification settings - Fork 1
/
icarus_server_mock.go
91 lines (80 loc) · 2.46 KB
/
icarus_server_mock.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
type dataColor struct {
R float64 `json:"r"`
G float64 `json:"g"`
B float64 `json:"b"`
}
type userData struct {
Devicedata deviceData `json:"devicedata"`
Gamedata []gameData `json:"gamedata"`
}
type deviceData struct {
ScreenDPI float64 `json:"screenDPI"`
ScreenHeight int `json:"screenHeight"`
ScreenWidth int `json:"screenWidth"`
}
type gameData struct {
LevelNum int `json:"levelNum"`
AnswerCorrect bool `json:"answerCorrect"`
ResponseTime float64 `json:"responseTime"`
TimeSinceStart float64 `json:"timeSinceStart"`
BladeQuDistance float64 `json:"bladeQuDistance"`
BladeQuBorderDistance float64 `json:"bladeQuBorderDistance"`
Colors []dataColor `json:"colors"`
GuessedColor int `json:"guessedColor"`
CorrectColor int `json:"correctColor"`
BackgroundColor dataColor `json:"backgroundColor"`
BorderRadius float64 `json:"borderRadius"`
NumberOfBlades int `json:"numberOfBlades"`
NQuSavedThisRun int `json:"nQuSavedThisRun"`
NTotalRun int `json:"nTotalRun"`
NLevelRun int `json:"nLevelRun"`
}
type icarusData struct {
Appdata struct {
Uuid string `json:"uuid"`
Voiceover bool `json:"voiceover"`
Device string `json:"device"`
Lang string `json:"lang"`
Appname string `json:"appname"`
Appversion int32 `json:"appversion"`
} `json:"appdata"`
Debug bool `json:"debug"`
Userdata userData `json:"userdata"`
Timestamp struct {
Utc string `json:"utc"`
User string `json:"user"`
} `json:"timestamp"`
}
func postHandler(rw http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
var data icarusData
ok := "OK"
if err := decoder.Decode(&data); err != nil {
log.Println("Format is not correct!")
ok = "KO"
} else {
log.Println("Format is OK")
}
if b, err := json.MarshalIndent(data, "", " "); err != nil {
fmt.Printf("error: %s\n", err.Error())
} else {
fmt.Println(string(b))
}
fmt.Printf("--------------EOF (%s, %d bytes)\n\n", ok, req.ContentLength)
}
func main() {
router := mux.NewRouter()
POST := router.Methods("POST").Subrouter()
POST.HandleFunc("/", postHandler)
http.Handle("/", router)
log.Println("Listening on 0.0.0.0:8000")
http.ListenAndServe(":8000", nil)
}