Documentation
¶
Overview ¶
Package feed creates RSS 2.0 and Atom 1.0 XML feeds from one shared model.
Index ¶
Examples ¶
Constants ¶
const ( // ContentTypeText renders Atom content as plain text. ContentTypeText = "text" // ContentTypeHTML renders Atom content as escaped HTML markup. ContentTypeHTML = "html" // ContentTypeXHTML renders Atom content as raw XHTML markup. ContentTypeXHTML = "xhtml" )
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse parses an RSS 2.0 or Atom 1.0 feed and returns the detected format.
Example ¶
package main
import (
"fmt"
"github.com/jor-go/feed"
)
func main() {
raw := []byte(`<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Example Feed</title>
<link>https://example.com</link>
<description>Latest posts</description>
<item>
<title>Hello</title>
<link>https://example.com/hello</link>
<description>A short post.</description>
</item>
</channel>
</rss>`)
f, format, err := feed.Parse(raw)
fmt.Println(err == nil)
fmt.Println(format)
fmt.Println(f.Items[0].Title)
}
Output: true rss Hello
Types ¶
type Category ¶
Category describes a category or tag. Domain maps to RSS domain and Atom scheme; Label is Atom-only.
type Content ¶
Content describes Atom entry content. Type defaults to "text"; "html" and "xhtml" are also supported.
type Enclosure ¶
Enclosure describes a media attachment. URL, Length, and Type are required by RSS 2.0 and map to Atom enclosure links.
type Feed ¶
type Feed struct {
Title string
Link string
Description string
ID string
// Updated is required for Atom and is rendered as RSS lastBuildDate.
Updated time.Time
// Published is rendered as RSS pubDate when set.
Published time.Time
Language string
Copyright string
Generator string
GeneratorURI string
GeneratorVersion string
Self string
TTL int
Authors []Person
Categories []Category
Image *Image
Items []Item
}
Feed contains the shared metadata and items that can be rendered as RSS 2.0 or Atom 1.0.
func (Feed) MarshalAtom ¶
MarshalAtom returns the Atom 1.0 XML document.
Example ¶
package main
import (
"fmt"
"strings"
"time"
"github.com/jor-go/feed"
)
func main() {
f := feed.New("Example Feed", "https://example.com", "Latest posts")
f.ID = "urn:example:feed"
f.Updated = time.Date(2026, 5, 13, 18, 0, 0, 0, time.UTC)
f.Authors = []feed.Person{{Name: "Jordan"}}
f.AddItem(feed.Item{
Title: "Hello",
Link: "https://example.com/hello",
ID: "urn:example:hello",
Updated: time.Date(2026, 5, 13, 18, 0, 0, 0, time.UTC),
Summary: "A short post.",
})
out, err := f.MarshalAtom()
fmt.Println(err == nil)
fmt.Println(strings.Contains(string(out), `xmlns="http://www.w3.org/2005/Atom"`))
}
Output: true true
func (Feed) MarshalRSS ¶
MarshalRSS returns the RSS 2.0 XML document.
Example ¶
package main
import (
"fmt"
"strings"
"time"
"github.com/jor-go/feed"
)
func main() {
f := feed.New("Example Feed", "https://example.com", "Latest posts")
f.AddItem(feed.Item{
Title: "Hello",
Link: "https://example.com/hello",
Description: "A short post.",
Published: time.Date(2026, 5, 13, 18, 0, 0, 0, time.UTC),
})
out, err := f.MarshalRSS()
fmt.Println(err == nil)
fmt.Println(strings.Contains(string(out), `<rss version="2.0">`))
}
Output: true true
func (Feed) ValidateAtom ¶
ValidateAtom validates the shared feed for Atom 1.0 output.
func (Feed) ValidateRSS ¶
ValidateRSS validates the shared feed for RSS 2.0 output.
type Item ¶
type Item struct {
Title string
Link string
Description string
Summary string
ID string
Updated time.Time
Published time.Time
Authors []Person
Categories []Category
Comments string
Content Content
Enclosures []Enclosure
}
Item contains shared entry metadata that can be rendered as an RSS item or Atom entry.
type ValidationError ¶
ValidationError describes one or more validation problems for a feed format.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string