Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteAll ¶ added in v1.3.1
WriteAll writes all files to the given output. Urlset files are written to writers provided by o.Urlset(), the function will call it every time a new file is to be written. The final index file is written to a writer provided by o.Index(). The function aborts if any unexpected error occurs when writing.
Example (Buffers) ¶
entries := []sitemap.UrlEntry{ { Loc: "http://goiguide.com/", LastMod: time.Date(2025, time.November, 2, 11, 34, 58, 123, time.UTC), }, { Loc: "http://goiguide.com/test/", Images: []string{ "http://goiguide.com/test/1.jpg", "http://goiguide.com/test/2.jpg", "http://goiguide.com/test/3.jpg", }, }, } var out bufferOutput err := sitemap.WriteAll(&out, &arrayInput{Arr: entries}) if err != nil { fmt.Printf("Error: %s\n", err) } for i := range out.UrlsetBufs { fmt.Printf("\n\n::: Urlset %d\n\n", i) fmt.Print(out.UrlsetBufs[i].String()) } fmt.Printf("\n\n::: Index\n\n") fmt.Print(out.IndexBuf.String())
Output: ::: Urlset 0 <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> <url> <loc>http://goiguide.com/</loc> <lastmod>2025-11-02T11:34:58Z</lastmod> </url> <url> <loc>http://goiguide.com/test/</loc> <image:image> <image:loc>http://goiguide.com/test/1.jpg</image:loc> </image:image> <image:image> <image:loc>http://goiguide.com/test/2.jpg</image:loc> </image:image> <image:image> <image:loc>http://goiguide.com/test/3.jpg</image:loc> </image:image> </url> </urlset> ::: Index <?xml version="1.0" encoding="UTF-8"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap> <loc>https://goiguide.com/sitemap-0.xml</loc> </sitemap> </sitemapindex>
Example (DynamicInput) ¶
err := sitemap.WriteAll(&stdoutOutput{}, &dynamicInput{Length: 3}) if err != nil { fmt.Printf("Error: %s\n", err) }
Output:
Example (Stdout) ¶
entries := []sitemap.UrlEntry{ { Loc: "http://goiguide.com/", LastMod: time.Date(2025, time.November, 2, 11, 34, 58, 123, time.UTC), }, { Loc: "http://goiguide.com/test/", Images: []string{ "http://goiguide.com/test/1.jpg", "http://goiguide.com/test/2.jpg", "http://goiguide.com/test/3.jpg", }, }, } err := sitemap.WriteAll(&stdoutOutput{}, &arrayInput{Arr: entries}) if err != nil { fmt.Printf("Error: %s\n", err) }
Output: ::: Urlset 0 <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> <url> <loc>http://goiguide.com/</loc> <lastmod>2025-11-02T11:34:58Z</lastmod> </url> <url> <loc>http://goiguide.com/test/</loc> <image:image> <image:loc>http://goiguide.com/test/1.jpg</image:loc> </image:image> <image:image> <image:loc>http://goiguide.com/test/2.jpg</image:loc> </image:image> <image:image> <image:loc>http://goiguide.com/test/3.jpg</image:loc> </image:image> </url> </urlset> ::: Index <?xml version="1.0" encoding="UTF-8"?> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap> <loc>https://goiguide.com/sitemap-0.xml</loc> </sitemap> </sitemapindex>
Types ¶
type ChannelInput ¶
type ChannelInput struct {
// contains filtered or unexported fields
}
func NewChannelInput ¶
func NewChannelInput(getUrlsetUrl func(int) string) *ChannelInput
func (*ChannelInput) Close ¶
func (in *ChannelInput) Close()
func (*ChannelInput) Feed ¶
func (in *ChannelInput) Feed(entry *UrlEntry)
func (*ChannelInput) GetUrlsetUrl ¶ added in v1.3.1
func (in *ChannelInput) GetUrlsetUrl(n int) string
func (*ChannelInput) Next ¶
func (in *ChannelInput) Next() *UrlEntry
Click to show internal directories.
Click to hide internal directories.