diff --git a/cmd/dwelling-home/main.go b/cmd/dwelling-home/main.go index 85ccbee..e644932 100644 --- a/cmd/dwelling-home/main.go +++ b/cmd/dwelling-home/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "log" + "net/http" "net/netip" "os" "os/signal" @@ -12,8 +13,10 @@ import ( "syscall" "time" - "git.arav.su/Arav/dwelling-home/internal/http" + dwhttp "git.arav.su/Arav/dwelling-home/internal/http" mfsqlite "git.arav.su/Arav/dwelling-home/pkg/mindflow/database/sqlite" + "git.arav.su/Arav/dwelling-home/web" + "git.arav.su/Arav/httpr" gb "git.arav.su/Arav/justguestbook" ) @@ -67,46 +70,52 @@ func main() { } defer mindflowDB.Close() - hand := http.NewHandlers(*captchaExpiry, *guestbookOwner, *guestbookPageSize, guestbookDB, mindflowDB) + hand := dwhttp.NewHandlers(*captchaExpiry, *guestbookOwner, *guestbookPageSize, guestbookDB, mindflowDB) - srv := http.NewHttpServer() + r := httpr.New() - srv.SetNotFoundHandler(http.NotFound) + r.NotFoundHandler = func(w http.ResponseWriter, _ *http.Request) { + web.ErrorXXX("/ Not Found", "", "", http.StatusNotFound, w) + } - srv.ServeStatic("/assets/*filepath", http.AssetsFS()) - srv.GET("/robots.txt", http.RobotsTxt) - srv.GET("/rss.xml", hand.RSS) - srv.GET("/sitemap.xml", http.SitemapXml) + r.ServeStatic("/assets/*filepath", web.Assets()) + r.Handler(http.MethodGet, "/robots.txt", dwhttp.RobotsTxt) + r.Handler(http.MethodGet, "/rss.xml", hand.RSS) + r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.SitemapXml) - srv.GET("/", hand.Index) - srv.GET("/stuff", hand.Stuff) - srv.GET("/stuff/article/*filepath", hand.Article) - srv.GET("/mindflow", hand.Mindflow) - srv.GET("/mindflow/admin", hand.MindflowAdmin) - srv.GET("/about", hand.About) - srv.GET("/guestbook", hand.Guestbook) - srv.GET("/guestbook/admin", hand.GuestbookAdmin) + r.Handler(http.MethodGet, "/", hand.Index) + r.Handler(http.MethodGet, "/stuff", hand.Stuff) + r.Handler(http.MethodGet, "/stuff/article/*filepath", hand.Article) + r.Handler(http.MethodGet, "/mindflow", hand.Mindflow) + r.Handler(http.MethodGet, "/mindflow/admin", hand.MindflowAdmin) + r.Handler(http.MethodGet, "/about", hand.About) + r.Handler(http.MethodGet, "/guestbook", hand.Guestbook) + r.Handler(http.MethodGet, "/guestbook/admin", hand.GuestbookAdmin) - captchaApi := http.NewCaptchaApiHandlers(*captchaExpiry) + captchaApi := dwhttp.NewCaptchaApiHandlers(*captchaExpiry) - srv.POST("/api/captcha/", captchaApi.New) - srv.POST("/api/captcha/:id", captchaApi.Solve) - srv.GET("/api/captcha/:id/image", captchaApi.Image) + 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) - guestbookApi := http.NewGuestbookApiHandlers(*guestbookOwner, *guestbookPageSize, guestbookDB) + guestbookApi := dwhttp.NewGuestbookApiHandlers(*guestbookOwner, *guestbookPageSize, guestbookDB) - srv.POST("/api/guestbook", guestbookApi.New) - srv.PATCH("/api/guestbook/:id", guestbookApi.Edit) - srv.DELETE("/api/guestbook/:id", guestbookApi.Delete) - srv.POST("/api/guestbook/:id/reply", guestbookApi.Reply) - srv.PATCH("/api/guestbook/:id/reply", guestbookApi.EditReply) - srv.DELETE("/api/guestbook/:id/reply", guestbookApi.DeleteReply) + 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) - mindflowApi := http.NewMindflowApiHandlers(mindflowDB) + mindflowApi := dwhttp.NewMindflowApiHandlers(mindflowDB) - srv.POST("/api/mindflow", mindflowApi.NewPost) - srv.PATCH("/api/mindflow/:id", mindflowApi.EditPost) - srv.DELETE("/api/mindflow/:id", mindflowApi.DeletePost) + 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) srv.POST("/api/mindflow-category", mindflowApi.NewCategory) srv.PATCH("/api/mindflow-category/:id", mindflowApi.EditCategory)