start building frontend
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -22,27 +22,14 @@ type AdminRouter struct {
|
||||
ts *tailscale.LocalClient
|
||||
}
|
||||
|
||||
type handler struct {
|
||||
get func()
|
||||
post func()
|
||||
put func()
|
||||
delete func()
|
||||
}
|
||||
type handler map[string]func()
|
||||
|
||||
func (h handler) Handle(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == http.MethodHead && h.get != nil {
|
||||
h.get()
|
||||
} else if req.Method == http.MethodGet && h.get != nil {
|
||||
h.get()
|
||||
} else if req.Method == http.MethodPost && h.post != nil {
|
||||
h.post()
|
||||
} else if req.Method == http.MethodPut && h.put != nil {
|
||||
h.put()
|
||||
} else if req.Method == http.MethodDelete && h.delete != nil {
|
||||
h.delete()
|
||||
} else {
|
||||
badMethod(w)
|
||||
if f, ok := h[req.Method]; ok {
|
||||
f()
|
||||
return
|
||||
}
|
||||
badMethod(w)
|
||||
}
|
||||
|
||||
func writeJSONerror(w http.ResponseWriter, err string, status int) {
|
||||
@@ -65,11 +52,11 @@ func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/records":
|
||||
handler{
|
||||
get: func() { getRecords(router.rcol, w, r) },
|
||||
http.MethodGet: func() { getRecords(router.rcol, w, r) },
|
||||
}.Handle(w, r)
|
||||
case "/api/books":
|
||||
handler{
|
||||
get: func() { getBooks(router.lib, w, r) },
|
||||
http.MethodGet: func() { getBooks(router.lib, w, r) },
|
||||
}.Handle(w, r)
|
||||
default:
|
||||
static(router.static).ServeHTTP(w, r)
|
||||
@@ -80,13 +67,13 @@ func (router *AdminRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api/whoami":
|
||||
handler{
|
||||
get: func() { getWhoAmI(router.ts, w, r) },
|
||||
http.MethodGet: func() { getWhoAmI(router.ts, w, r) },
|
||||
}.Handle(w, r)
|
||||
case "/api/books":
|
||||
handler{
|
||||
get: func() { getBooks(router.lib, w, r) },
|
||||
post: func() { addBook(router.lib, w, r) },
|
||||
delete: func() { deleteBook(router.lib, w, r) },
|
||||
http.MethodGet: func() { getBooks(router.lib, w, r) },
|
||||
http.MethodPost: func() { addBook(router.lib, w, r) },
|
||||
http.MethodDelete: func() { deleteBook(router.lib, w, r) },
|
||||
}.Handle(w, r)
|
||||
default:
|
||||
static(router.static).ServeHTTP(w, r)
|
||||
|
Reference in New Issue
Block a user