Skip to content

Commit

Permalink
API remove stream consumers (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnjooiopa authored Aug 30, 2024
1 parent ec1d82e commit 7445123
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions internal/streams/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,32 @@ func apiStreamsSpeed(w http.ResponseWriter, r *http.Request) {

http.Error(w, "", http.StatusNotFound)
}

func apiStreamsRemoveConsumers(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "", http.StatusNotFound)
return
}

query := r.URL.Query()

for _, streamName := range query["name"] {
if streamName == "" {
continue
}

streamsMu.RLock()
stream := Get(streamName)
streamsMu.RUnlock()

if stream == nil {
continue
}

for _, consumer := range stream.consumers {
stream.RemoveConsumer(consumer)
}
}

http.Error(w, "", http.StatusOK)
}
1 change: 1 addition & 0 deletions internal/streams/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func Init() {

// custom
api.HandleFunc("api/custom/streams/speed", apiStreamsSpeed)
api.HandleFunc("api/custom/streams.removeConsumers", apiStreamsRemoveConsumers)

if cfg.Publish == nil {
return
Expand Down

0 comments on commit 7445123

Please sign in to comment.