diff --git a/internal/streams/streams.go b/internal/streams/streams.go index afc6c4d3..987744c6 100644 --- a/internal/streams/streams.go +++ b/internal/streams/streams.go @@ -148,9 +148,15 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) { // Not sure about all this API. Should be rewrited... switch r.Method { case "GET": + streamsMu.RLock() + defer streamsMu.RUnlock() + api.ResponsePrettyJSON(w, streams[src]) case "PUT": + apiMu.Lock() + defer apiMu.Unlock() + name := query.Get("name") if name == "" { name = src @@ -198,6 +204,9 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) { } case "DELETE": + apiMu.Lock() + defer apiMu.Unlock() + delete(streams, src) if err := app.PatchConfig(src, nil, "streams"); err != nil { @@ -208,4 +217,5 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) { var log zerolog.Logger var streams = map[string]*Stream{} -var streamsMu sync.Mutex +var streamsMu sync.RWMutex +var apiMu sync.Mutex