Last update: 2025-12-21
Simple Sitemap HTTP Handler in Go
package web
func SitemapXMLHandler(domain string, paths []string) http.HandlerFunc {
v := "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"
for _, path := range paths {
v += "\t<url>\n"
v += "\t<loc>https://" + domain + path + "</loc>\n"
v += "\t</url>\n"
}
v += "</urlset>\n"
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/xml; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.WriteHeader(http.StatusOK)
io.WriteString(w, v)
}
}