Sitemap library for golang.
seo
Find a file
2025-06-17 22:26:08 +05:00
examples Initial commit 2025-06-16 13:50:33 +05:00
go.mod Initial commit 2025-06-16 13:50:33 +05:00
LICENSE.md Initial commit 2025-06-16 13:50:33 +05:00
Makefile Initial commit 2025-06-16 13:50:33 +05:00
README.md Add a link to pkg.go.dev 2025-06-17 22:26:08 +05:00
sitemap.go Initial commit 2025-06-16 13:50:33 +05:00
sitemap_test.go Initial commit 2025-06-16 13:50:33 +05:00
template.go Initial commit 2025-06-16 13:50:33 +05:00
template_test.go Initial commit 2025-06-16 13:50:33 +05:00

Sitemap

Go Reference

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)
	}
}