backend code

This commit is contained in:
2025-08-24 15:55:44 +02:00
parent 14a03d6a77
commit 4e1b4bad0a
7 changed files with 383 additions and 2 deletions

28
server/twitch/rest.go Normal file
View File

@@ -0,0 +1,28 @@
package twitch
import (
"encoding/json"
"net/http"
)
type addUserReq struct {
User string `json:"user"`
}
func MonitorUserHandler(m *Monitor) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req addUserReq
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
m.Add(req.User)
if err := json.NewEncoder(w).Encode("ok"); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}