Iris provides extensive support for the Sitemap Protocol which automatically generates sitemap index "/sitemap.xml" too.
To enable sitemaps on your web application you should use the iris.WithSitemap Configurator. This function accepts the full scheme and domain of the exposed application.
app := iris.New()
// [...]
app.Listen(":8080", iris.WithSitemap("http://localhost:8080"))
The application will loop through registered static routes and it will add each one of them to the sitemap file. By default only the <loc> XML element will be filled unless the route's fields LastMod, ChangeFreq or/and Priority* are set.
app.Get("/home", handler).SetLastMod(time.Now()).SetChangeFreq("hourly").SetPriority(0.8)
A static route is exposed on GET HTTP Method and its path does not contain a dynamic parameter. e.g. /home, /about but not /user/{id:uint64} and e.t.c.
See it in action, download and run the example from:
If the application is localized then iris.WithSitemap will add xhtml:link XML elements to the sitemap file for each translation language as recommended at: Read more about it at the Localization section.
Export as PDF
Copy link