Add general info API

This commit is contained in:
Alexey Khit
2023-01-14 18:00:43 +03:00
parent 7c1f48e0ad
commit e472397705
3 changed files with 23 additions and 3 deletions
+14
View File
@@ -9,6 +9,7 @@ import (
"net/http"
"os"
"strconv"
"sync"
)
func Init() {
@@ -37,6 +38,7 @@ func Init() {
initStatic(cfg.Mod.StaticDir)
initWS(cfg.Mod.Origin)
HandleFunc("api", apiHandler)
HandleFunc("api/config", configHandler)
HandleFunc("api/exit", exitHandler)
HandleFunc("api/streams", streamsHandler)
@@ -100,6 +102,18 @@ func middlewareCORS(next http.Handler) http.Handler {
})
}
var mu sync.Mutex
func apiHandler(w http.ResponseWriter, r *http.Request) {
mu.Lock()
app.Info["host"] = r.Host
mu.Unlock()
if err := json.NewEncoder(w).Encode(app.Info); err != nil {
log.Warn().Err(err).Caller().Send()
}
}
func exitHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "", http.StatusBadRequest)