-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint_list_methods.go
48 lines (39 loc) · 1.06 KB
/
endpoint_list_methods.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package v2
import (
"encoding/json"
"net/http"
"sort"
vfmt "github.com/elysiumstation/fury/libs/fmt"
"github.com/elysiumstation/fury/logging"
"github.com/julienschmidt/httprouter"
)
type ListMethodsResponse struct {
RegisteredMethods []string `json:"registeredMethods"`
}
func (a *API) ListMethods(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
a.log.Info("New request",
logging.String("url", vfmt.Escape(r.URL.String())),
)
registeredMethods := make([]string, 0, len(a.commands))
for method := range a.commands {
registeredMethods = append(registeredMethods, method)
}
sort.Strings(registeredMethods)
body, _ := json.Marshal(Response{
Result: ListMethodsResponse{
RegisteredMethods: registeredMethods,
},
})
w.WriteHeader(http.StatusOK)
if _, err := w.Write(body); err != nil {
w.WriteHeader(http.StatusInternalServerError)
a.log.Info("Internal error",
logging.Int("http-status", http.StatusInternalServerError),
logging.Error(err),
)
return
}
a.log.Info("Success",
logging.Int("http-status", http.StatusOK),
)
}