forked from hswaw/hscloud
wow: implement spaceapi
Change-Id: I4b9f08801ae37d2b85de9b089bf09731cfd7dbe6
This commit is contained in:
parent
54d0e977e5
commit
7ea8e472ad
4 changed files with 38 additions and 1 deletions
|
@ -9,7 +9,7 @@ local kube = import "../../../kube/kube.libsonnet";
|
|||
prefix: "",
|
||||
images: {
|
||||
acore: "registry.k0.hswaw.net/q3k/azerothcore-wowtlk:1606950998",
|
||||
panel: "registry.k0.hswaw.net/q3k/panel:1607033741-f18a531f9b84c5b33653c8db5d64aaa0af337541",
|
||||
panel: "registry.k0.hswaw.net/q3k/panel:1607075221-54d0e977e57cc2c8d949c3a7ecf2ff21abd9d143",
|
||||
},
|
||||
db: {
|
||||
local mkConfig = function(name) {
|
||||
|
|
|
@ -7,6 +7,7 @@ go_library(
|
|||
srcs = [
|
||||
"main.go",
|
||||
"soap.go",
|
||||
"spaceapi.go",
|
||||
],
|
||||
importpath = "code.hackerspace.pl/hscloud/personal/q3k/wow/panel",
|
||||
visibility = ["//visibility:private"],
|
||||
|
|
|
@ -115,6 +115,7 @@ func main() {
|
|||
http.HandleFunc("/setup", s.viewOauthSetup)
|
||||
http.HandleFunc("/reset", s.viewReset)
|
||||
http.HandleFunc("/logout", s.viewLogout)
|
||||
http.HandleFunc("/spaceapi", s.viewSpaceAPI)
|
||||
|
||||
err = http.ListenAndServe(flagListen, nil)
|
||||
if err != nil {
|
||||
|
|
35
personal/q3k/wow/panel/spaceapi.go
Normal file
35
personal/q3k/wow/panel/spaceapi.go
Normal file
|
@ -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)
|
||||
}
|
Loading…
Reference in a new issue