sitemap/README.md

43 lines
776 B
Markdown

# Sitemap
[![Go Reference](https://pkg.go.dev/badge/code.app-house.ru/go/sitemap.svg)](https://pkg.go.dev/code.app-house.ru/go/sitemap)
Sitemap library for golang.
## Usage
```go
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)
}
}
```