Sitemap library for golang.
examples | ||
go.mod | ||
LICENSE.md | ||
Makefile | ||
README.md | ||
sitemap.go | ||
sitemap_test.go | ||
template.go | ||
template_test.go |
Sitemap
Sitemap library for golang.
Usage
package main
import (
"log/slog"
"net/http"
"time"
"code.app-house.ru/go/sitemap"
)
var (
urlset = []sitemap.URL{
sitemap.URL{
Loc: "https://example.com/",
LastMod: time.Date(2025, time.June, 1, 0, 0, 0, 0, time.Local),
ChangeFreq: sitemap.ChangeFreqMonthly,
Priority: 1.0,
},
}
)
func main() {
http.HandleFunc("/sitemap.xml", sitemapHandler)
http.ListenAndServe(":8080", nil)
}
func sitemapHandler(w http.ResponseWriter, r *http.Request) {
err := sitemap.Execute(w, urlset)
if err != nil {
slog.Error("can't render sitemap", "err", err)
}
}