Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
github.com/PlanitarInc/go-sitemap
A GO library for generating Sitemap XML files.
package main
import (
"bytes"
"fmt"
"io"
"time"
sitemap "github.com/PlanitarInc/go-sitemap"
)
type SitemapOutput struct {
IndexBuf bytes.Buffer
UrlsetBufs []bytes.Buffer
}
func (out *SitemapOutput) Index() io.Writer {
return &out.IndexBuf
}
func (out *SitemapOutput) Urlset() io.Writer {
out.UrlsetBufs = append(out.UrlsetBufs, bytes.Buffer{})
return &out.UrlsetBufs[len(out.UrlsetBufs)-1]
}
type ArrayInput struct {
Arr []sitemap.UrlEntry
nextIdx int
}
func (a *ArrayInput) Next() *sitemap.UrlEntry {
if a.nextIdx >= len(a.Arr) {
return nil
}
a.nextIdx++
return &a.Arr[a.nextIdx-1]
}
func (a *ArrayInput) GetUrlsetUrl(n int) string {
return fmt.Sprintf("https://goiguide.com/sitemap-%d.xml", n)
}
func main() {
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 SitemapOutput
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())
}
The 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>
The library is trying to be smart when producing XML and keeps the allocations
constant. That is, space complexity is O(1)
-- it does not depend on the
number of entries.
$ go test -run '^$' -bench . -benchmem
goos: darwin
goarch: amd64
pkg: github.com/PlanitarInc/go-sitemap
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkWriteAll/1-12 1328336 945.2 ns/op 128 B/op 3 allocs/op
BenchmarkWriteAll/10-12 150031 6808 ns/op 128 B/op 3 allocs/op
BenchmarkWriteAll/100-12 17624 62340 ns/op 128 B/op 3 allocs/op
BenchmarkWriteAll/1000-12 1898 627547 ns/op 128 B/op 3 allocs/op
BenchmarkWriteAll/10000-12 192 6315018 ns/op 128 B/op 3 allocs/op
BenchmarkWriteAll/100000-12 18 62742897 ns/op 160 B/op 4 allocs/op
BenchmarkWriteAll/1000000-12 2 632302752 ns/op 736 B/op 22 allocs/op
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.