wow: implement spaceapi
Change-Id: I4b9f08801ae37d2b85de9b089bf09731cfd7dbe6
diff --git a/personal/q3k/wow/panel/spaceapi.go b/personal/q3k/wow/panel/spaceapi.go
new file mode 100644
index 0000000..94923d2
--- /dev/null
+++ b/personal/q3k/wow/panel/spaceapi.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "encoding/json"
+ "net/http"
+)
+
+type PeopleNowPresent struct {
+ Names []string `json:"names"`
+ Value int `json:"value"`
+}
+
+type SpaceAPI struct {
+ Sensors struct {
+ PeopleNowPresent []PeopleNowPresent `json:"people_now_present"`
+ } `json:"sensors"`
+}
+
+func (s *server) viewSpaceAPI(w http.ResponseWriter, r *http.Request) {
+ res := &SpaceAPI{}
+
+ names := []string{}
+ for _, p := range s.online(r.Context()) {
+ names = append(names, p.Character)
+ }
+ res.Sensors.PeopleNowPresent = []PeopleNowPresent{
+ {
+ Names: names,
+ Value: len(names),
+ },
+ }
+
+ w.Header().Set("Content-Type", "application/json")
+ json.NewEncoder(w).Encode(res)
+}