ikeikeikeike / go-sitemap-generator

go-sitemap-generator is the easiest way to generate Sitemaps in Go
https://github.com/ikeikeikeike/go-sitemap-generator
MIT License
218 stars 65 forks source link

Allow to get XML content without writing to the file system #4

Closed sungwoncho closed 7 years ago

sungwoncho commented 8 years ago

I would like to be able to get an XML content without having to create a sitemap.xml.gz.

In my app, I plan to generate and serve a sitemap on the fly when the client requests one. The reason is that the content changes frequently and I would rather make the sitemap dynamic based on the current database.

An implementation looks something like this.

func SitemapHandler(w http.ResponseWriter, r *http.Request) {
    sm := stm.NewSitemap()
    sm.Create()

    sm.Add(stm.URL{
        "loc": "...",
    })
        ...

    xml := sm.XMLContent()
    w.Header().Set("Content-Type", "application/xml")
    w.Write(xml)
}

Basically, it'd be great if Sitemap had a method like XMLContent() that returns a raw XML content of the sitemap. I will open a PR.