forked from hibiken/asynqmon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_handlers.go
34 lines (29 loc) · 897 Bytes
/
server_handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package asynqmon
import (
"encoding/json"
"net/http"
"github.com/hibiken/asynq"
)
// ****************************************************************************
// This file defines:
// - http.Handler(s) for server related endpoints
// ****************************************************************************
type listServersResponse struct {
Servers []*serverInfo `json:"servers"`
}
func newListServersHandlerFunc(inspector *asynq.Inspector, pf PayloadFormatter) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
srvs, err := inspector.Servers()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
resp := listServersResponse{
Servers: toServerInfoList(srvs, pf),
}
if err := json.NewEncoder(w).Encode(resp); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}