From a6bec0db7541736a971278ef4c1bfc8de4209a00 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 12 Aug 2023 23:52:52 +0400 Subject: [PATCH] Made use of httpr.Router.Sub() functionality. --- cmd/dwelling-home/main.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cmd/dwelling-home/main.go b/cmd/dwelling-home/main.go index dcd2baa..e0aadfd 100644 --- a/cmd/dwelling-home/main.go +++ b/cmd/dwelling-home/main.go @@ -96,27 +96,30 @@ func main() { captchaApi := dwhttp.NewCaptchaApiHandlers(*captchaExpiry) - r.Handler(http.MethodPost, "/api/captcha", captchaApi.New) - r.Handler(http.MethodPost, "/api/captcha/:id", captchaApi.Solve) - r.Handler(http.MethodGet, "/api/captcha/:id/image", captchaApi.Image) + s := r.Sub("/api/captcha") + s.Handler(http.MethodPost, "/", captchaApi.New) + s.Handler(http.MethodPost, "/:id", captchaApi.Solve) + s.Handler(http.MethodGet, "/:id/image", captchaApi.Image) guestbookApi := dwhttp.NewGuestbookApiHandlers(*guestbookOwner, *guestbookPageSize, guestbookDB) - r.Handler(http.MethodPost, "/api/guestbook", guestbookApi.New) - r.Handler(http.MethodPatch, "/api/guestbook/:id", guestbookApi.Edit) - r.Handler(http.MethodDelete, "/api/guestbook/:id", guestbookApi.Delete) - r.Handler(http.MethodPost, "/api/guestbook/:id/reply", guestbookApi.Reply) - r.Handler(http.MethodPatch, "/api/guestbook/:id/reply", guestbookApi.EditReply) - r.Handler(http.MethodDelete, "/api/guestbook/:id/reply", guestbookApi.DeleteReply) + s = r.Sub("/api/guestbook") + s.Handler(http.MethodPost, "/", guestbookApi.New) + s.Handler(http.MethodPatch, "/:id", guestbookApi.Edit) + s.Handler(http.MethodDelete, "/:id", guestbookApi.Delete) + s.Handler(http.MethodPost, "/:id/reply", guestbookApi.Reply) + s.Handler(http.MethodPatch, "/:id/reply", guestbookApi.EditReply) + s.Handler(http.MethodDelete, "/:id/reply", guestbookApi.DeleteReply) mindflowApi := dwhttp.NewMindflowApiHandlers(mindflowDB) - r.Handler(http.MethodPost, "/api/mindflow", mindflowApi.NewPost) - r.Handler(http.MethodPatch, "/api/mindflow/:id", mindflowApi.EditPost) - r.Handler(http.MethodDelete, "/api/mindflow/:id", mindflowApi.DeletePost) - r.Handler(http.MethodPost, "/api/mindflow/category", mindflowApi.NewCategory) - r.Handler(http.MethodPatch, "/api/mindflow/category/:id", mindflowApi.EditCategory) - r.Handler(http.MethodDelete, "/api/mindflow/category/:id", mindflowApi.DeleteCategory) + s = r.Sub("/api/mindflow") + s.Handler(http.MethodPost, "/", mindflowApi.NewPost) + s.Handler(http.MethodPatch, "/:id", mindflowApi.EditPost) + s.Handler(http.MethodDelete, "/:id", mindflowApi.DeletePost) + s.Handler(http.MethodPost, "/category", mindflowApi.NewCategory) + s.Handler(http.MethodPatch, "/category/:id", mindflowApi.EditCategory) + s.Handler(http.MethodDelete, "/category/:id", mindflowApi.DeleteCategory) srv := dwhttp.NewHttpServer(r)