github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/server_handlers.go (about) 1 package asynqmon 2 3 import ( 4 "net/http" 5 6 "github.com/wfusion/gofusion/common/infra/asynq" 7 "github.com/wfusion/gofusion/common/utils/serialize/json" 8 ) 9 10 // **************************************************************************** 11 // This file defines: 12 // - http.Handler(s) for server related endpoints 13 // **************************************************************************** 14 15 type listServersResponse struct { 16 Servers []*serverInfo `json:"servers"` 17 } 18 19 func newListServersHandlerFunc(inspector *asynq.Inspector, pf PayloadFormatter) http.HandlerFunc { 20 return func(w http.ResponseWriter, r *http.Request) { 21 srvs, err := inspector.Servers() 22 if err != nil { 23 http.Error(w, err.Error(), http.StatusInternalServerError) 24 return 25 } 26 resp := listServersResponse{ 27 Servers: toServerInfoList(srvs, pf), 28 } 29 if err := json.NewEncoder(w).Encode(resp); err != nil { 30 http.Error(w, err.Error(), http.StatusInternalServerError) 31 return 32 } 33 } 34 }