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.
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.
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.
Example Code:
packagemainimport ("time""github.com/kataras/iris/v12")const startURL ="http://localhost:8080"funcmain() { app := newApp()// http://localhost:8080/sitemap.xml// Lists only online GET static routes.//// Reference: https://www.sitemaps.org/protocol.html app.Listen(":8080", iris.WithSitemap(startURL))}funcnewApp() *iris.Application { app := iris.New() app.Logger().SetLevel("debug") lastModified, _ := time.Parse("2006-01-02T15:04:05-07:00", "2019-12-13T21:50:33+02:00") app.Get("/home", handler).SetLastMod(lastModified).SetChangeFreq("hourly").SetPriority(1) app.Get("/articles", handler).SetChangeFreq("daily") app.Get("/path1", handler) app.Get("/path2", handler) app.Post("/this-should-not-be-listed", handler) app.Get("/this/{myparam}/should/not/be/listed", handler) app.Get("/this-should-not-be-listed-offline", handler).SetStatusOffline()// These should be excluded as well app.Get("/about", handler).ExcludeSitemap() app.Get("/offline", handler).SetStatusOffline()return app}funchandler(ctx iris.Context) { ctx.WriteString(ctx.Path()) }
Localization
Sitemap translations are automatically set to each route by path prefix if app.I18n.PathRedirect is true or by subdomain if app.I18n.Subdomain is true or by URL query parameter if app.I18n.URLParameter is not empty.