Initial commit
This commit is contained in:
commit
e3da3b9c7a
9 changed files with 929 additions and 0 deletions
41
README.md
Normal file
41
README.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
# 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)
|
||||
}
|
||||
}
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue