1
0
Fork 0

Endpoints reorganised a little. Handlers for assets are moved out of Handlers struct as a self-sustained funcs.

This commit is contained in:
Alexander Andreev 2023-05-22 03:16:38 +04:00
parent 183eb74ada
commit e856a4b930
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 11 additions and 11 deletions

View File

@ -72,7 +72,11 @@ func main() {
srv.SetNotFoundHandler(http.NotFound)
srv.ServeStatic("/assets/*filepath", hand.AssetsFS())
srv.ServeStatic("/assets/*filepath", http.AssetsFS())
srv.GET("/robots.txt", http.RobotsTxt)
srv.GET("/rss.xml", hand.RSS)
srv.GET("/sitemap.xml", http.SitemapXml)
srv.GET("/", hand.Index)
srv.GET("/stuff", hand.Stuff)
srv.GET("/stuff/article/*filepath", hand.Article)
@ -82,10 +86,6 @@ func main() {
srv.GET("/guestbook", hand.Guestbook)
srv.GET("/guestbook/admin", hand.GuestbookAdmin)
srv.GET("/robots.txt", hand.Robots)
srv.GET("/rss.xml", hand.RSS)
srv.GET("/sitemap.xml", hand.Sitemap)
captchaApi := http.NewCaptchaApiHandlers(*captchaExpiry)
srv.POST("/api/captcha/", captchaApi.New)

View File

@ -38,10 +38,6 @@ func (h *Handlers) CloseDB() {
h.guestbookDB.Close()
}
func (h *Handlers) AssetsFS() http.FileSystem {
return web.Assets()
}
func (h *Handlers) Index(w http.ResponseWriter, r *http.Request) {
web.Index("", w)
}
@ -160,12 +156,16 @@ func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) {
web.RSS(r.URL.Scheme+"://"+r.Host, "Arav", posts, r, w)
}
func (h *Handlers) Robots(w http.ResponseWriter, r *http.Request) {
func AssetsFS() http.FileSystem {
return web.Assets()
}
func RobotsTxt(w http.ResponseWriter, r *http.Request) {
data, _ := web.AssetsGetFile("robots.txt")
w.Write(data)
}
func (h *Handlers) Sitemap(w http.ResponseWriter, r *http.Request) {
func SitemapXml(w http.ResponseWriter, r *http.Request) {
data, _ := web.AssetsGetFile("sitemap.xml")
w.Write(data)
}