mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-09-24 14:22:09 +08:00
Add list groups REST endpoint
This commit is contained in:
33
group_handlers.go
Normal file
33
group_handlers.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package asynqmon
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
type listGroupsResponse struct {
|
||||
Groups []*groupInfo `json:"groups"`
|
||||
}
|
||||
|
||||
func newListGroupsHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
qname := mux.Vars(r)["qname"]
|
||||
|
||||
groups, err := inspector.Groups(qname)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
resp := listGroupsResponse{
|
||||
Groups: toGroupInfos(groups),
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user