1
0

A set of funcs to serve certain files was replaced by ServeAsset() func where you have to pass a path to an asset within an asset dir.

This commit is contained in:
Alexander Andreev 2024-04-20 04:52:35 +04:00
parent dca3804090
commit f9dabbc6f9
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
2 changed files with 11 additions and 20 deletions

View File

@ -60,10 +60,10 @@ func main() {
} }
r.ServeStatic("/assets/*filepath", web.Assets()) r.ServeStatic("/assets/*filepath", web.Assets())
r.Handler(http.MethodGet, "/favicon.ico", dwhttp.FaviconIco) r.Handler(http.MethodGet, "/favicon.ico", dwhttp.ServeAsset("img/favicon.ico"))
r.Handler(http.MethodGet, "/robots.txt", dwhttp.RobotsTxt) r.Handler(http.MethodGet, "/robots.txt", dwhttp.ServeAsset("robots.txt"))
r.Handler(http.MethodGet, "/rss.xml", hand.RSS) r.Handler(http.MethodGet, "/rss.xml", hand.RSS)
r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.SitemapXml) r.Handler(http.MethodGet, "/sitemap.xml", dwhttp.ServeAsset("sitemap.xml"))
r.Handler(http.MethodGet, "/", hand.Index) r.Handler(http.MethodGet, "/", hand.Index)
r.Handler(http.MethodGet, "/privacy", hand.Privacy) r.Handler(http.MethodGet, "/privacy", hand.Privacy)

View File

@ -168,29 +168,20 @@ func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
return return
} }
var scheme string
if r.Header.Get("Scheme") != "" { scheme := r.Header.Get("Scheme")
scheme = r.Header.Get("Scheme") if scheme == "" {
} else {
scheme = "http" scheme = "http"
} }
web.RSS(scheme+"://"+r.Host, h.owner, posts, r, w) web.RSS(scheme+"://"+r.Host, h.owner, posts, r, w)
} }
func FaviconIco(w http.ResponseWriter, r *http.Request) { func ServeAsset(path string) func(http.ResponseWriter, *http.Request) {
data, _ := web.AssetsGetFile("img/favicon.ico") return func(w http.ResponseWriter, r *http.Request) {
w.Write(data) data, _ := web.AssetsGetFile(path)
}
func RobotsTxt(w http.ResponseWriter, r *http.Request) {
data, _ := web.AssetsGetFile("robots.txt")
w.Write(data)
}
func SitemapXml(w http.ResponseWriter, r *http.Request) {
data, _ := web.AssetsGetFile("sitemap.xml")
w.Write(data) w.Write(data)
}
} }
func Error(w http.ResponseWriter, code int, reason, message, referer string) { func Error(w http.ResponseWriter, code int, reason, message, referer string) {