-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdm.go
41 lines (34 loc) · 948 Bytes
/
dm.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
package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"github.com/steffantucker/initiative-tracker/actor"
)
func nextHandler(w http.ResponseWriter, r *http.Request) {
combatents.NextTurn()
w.Header().Set("Content-Type", "text/json")
write, _ := json.Marshal(map[string]bool{"success": true})
w.Write(write)
}
func newHandler(w http.ResponseWriter, r *http.Request) {
newActor := actor.Actor{}
body, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(body, &newActor)
err := combatents.Add(newActor)
var write []byte
if err != nil {
write, _ = json.Marshal(map[string]bool{"success": false})
} else {
write, _ = json.Marshal(map[string]bool{"success": true})
}
w.Write(write)
}
func getHandler(w http.ResponseWriter, r *http.Request) {
w.Write(combatents.JSON())
}
func endHandler(w http.ResponseWriter, r *http.Request) {
combatents.Clear()
write, _ := json.Marshal(map[string]bool{"success": true})
w.Write(write)
}