-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.go
49 lines (41 loc) · 773 Bytes
/
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
package mock
import (
"encoding/json"
"net/http"
"github.com/go-chi/chi"
)
type mockServer struct {
router *chi.Mux
}
func New() http.Handler {
srv := &mockServer{
router: chi.NewRouter(),
}
srv.routes()
return srv.router
}
func (s *mockServer) handleRoot() http.HandlerFunc {
type id struct {
PlayerName string `json:"playerName"`
}
type player struct {
X float32 `json:"x"`
Y float32 `json:"y"`
ID id `json:"id"`
}
return func(w http.ResponseWriter, r *http.Request) {
players := []player{
{
X: 0.0,
Y: 0.0,
ID: id{
PlayerName: "Test",
},
},
}
if err := json.NewEncoder(w).Encode(players); err != nil {
http.Error(w, "failed to marshal players", http.StatusInternalServerError)
return
}
}
}