-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.go
34 lines (31 loc) · 1.05 KB
/
item.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package rss2
import (
"encoding/xml"
"fmt"
)
// Item represents an rss item. At least Title or Description must be
// present.
type Item struct {
XMLName xml.Name `xml:"item"`
Title string `xml:"title,omitempty"`
Link string `xml:"link,omitempty"`
Description string `xml:"description,omitempty"`
Author string `xml:"author,omitempty"`
Categories []*Category `xml:"category,omitempty"`
Comments string `xml:"comments,omitempty"`
Enclosure *Enclosure `xml:"enclosure,omitempty"`
GUID *GUID `xml:"guid,omitempty"`
PubDate *RSSTime `xml:"pubDate,omitempty"`
Source *Source `xml:"source,omitempty"`
}
// NewItem creates a new Item. Either title or description may be empty.
func NewItem(title, description string) (*Item, error) {
if len(title) == 0 && len(description) == 0 {
return nil, fmt.Errorf(`cannot create item with empty title and description`)
}
return &Item{
XMLName: xml.Name{Local: `item`},
Title: title,
Description: description,
}, nil
}