1
0

Made use of my own httpr router. /api/minflow-category was changed to /api/minflow/category.

This commit is contained in:
Alexander Andreev 2023-05-27 20:59:05 +04:00
parent fa25cff2de
commit 804d46f14e
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"net/http"
"net/netip" "net/netip"
"os" "os"
"os/signal" "os/signal"
@ -12,8 +13,10 @@ import (
"syscall" "syscall"
"time" "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" 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" gb "git.arav.su/Arav/justguestbook"
) )
@ -67,46 +70,52 @@ func main() {
} }
defer mindflowDB.Close() 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()) r.ServeStatic("/assets/*filepath", web.Assets())
srv.GET("/robots.txt", http.RobotsTxt) r.Handler(http.MethodGet, "/robots.txt", dwhttp.RobotsTxt)
srv.GET("/rss.xml", hand.RSS) r.Handler(http.MethodGet, "/rss.xml", hand.RSS)
srv.GET("/sitemap.xml", http.SitemapXml) r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.SitemapXml)
srv.GET("/", hand.Index) r.Handler(http.MethodGet, "/", hand.Index)
srv.GET("/stuff", hand.Stuff) r.Handler(http.MethodGet, "/stuff", hand.Stuff)
srv.GET("/stuff/article/*filepath", hand.Article) r.Handler(http.MethodGet, "/stuff/article/*filepath", hand.Article)
srv.GET("/mindflow", hand.Mindflow) r.Handler(http.MethodGet, "/mindflow", hand.Mindflow)
srv.GET("/mindflow/admin", hand.MindflowAdmin) r.Handler(http.MethodGet, "/mindflow/admin", hand.MindflowAdmin)
srv.GET("/about", hand.About) r.Handler(http.MethodGet, "/about", hand.About)
srv.GET("/guestbook", hand.Guestbook) r.Handler(http.MethodGet, "/guestbook", hand.Guestbook)
srv.GET("/guestbook/admin", hand.GuestbookAdmin) r.Handler(http.MethodGet, "/guestbook/admin", hand.GuestbookAdmin)
captchaApi := http.NewCaptchaApiHandlers(*captchaExpiry) captchaApi := dwhttp.NewCaptchaApiHandlers(*captchaExpiry)
srv.POST("/api/captcha/", captchaApi.New) r.Handler(http.MethodPost, "/api/captcha", captchaApi.New)
srv.POST("/api/captcha/:id", captchaApi.Solve) r.Handler(http.MethodPost, "/api/captcha/:id", captchaApi.Solve)
srv.GET("/api/captcha/:id/image", captchaApi.Image) 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) r.Handler(http.MethodPost, "/api/guestbook", guestbookApi.New)
srv.PATCH("/api/guestbook/:id", guestbookApi.Edit) r.Handler(http.MethodPatch, "/api/guestbook/:id", guestbookApi.Edit)
srv.DELETE("/api/guestbook/:id", guestbookApi.Delete) r.Handler(http.MethodDelete, "/api/guestbook/:id", guestbookApi.Delete)
srv.POST("/api/guestbook/:id/reply", guestbookApi.Reply) r.Handler(http.MethodPost, "/api/guestbook/:id/reply", guestbookApi.Reply)
srv.PATCH("/api/guestbook/:id/reply", guestbookApi.EditReply) r.Handler(http.MethodPatch, "/api/guestbook/:id/reply", guestbookApi.EditReply)
srv.DELETE("/api/guestbook/:id/reply", guestbookApi.DeleteReply) r.Handler(http.MethodDelete, "/api/guestbook/:id/reply", guestbookApi.DeleteReply)
mindflowApi := http.NewMindflowApiHandlers(mindflowDB) mindflowApi := dwhttp.NewMindflowApiHandlers(mindflowDB)
srv.POST("/api/mindflow", mindflowApi.NewPost) r.Handler(http.MethodPost, "/api/mindflow", mindflowApi.NewPost)
srv.PATCH("/api/mindflow/:id", mindflowApi.EditPost) r.Handler(http.MethodPatch, "/api/mindflow/:id", mindflowApi.EditPost)
srv.DELETE("/api/mindflow/:id", mindflowApi.DeletePost) 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.POST("/api/mindflow-category", mindflowApi.NewCategory)
srv.PATCH("/api/mindflow-category/:id", mindflowApi.EditCategory) srv.PATCH("/api/mindflow-category/:id", mindflowApi.EditCategory)