rss-tools/app/atom/atom.go (view raw)
| 1 | // Based on golang.org/x/tools/blog/atom. |
| 2 | |
| 3 | package atom |
| 4 | |
| 5 | import ( |
| 6 | "encoding/xml" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | const xhtmlNamespace = "http://www.w3.org/1999/xhtml" |
| 11 | |
| 12 | // Feed represents an Atom feed. |
| 13 | type Feed struct { |
| 14 | XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"` |
| 15 | Title string `xml:"title"` |
| 16 | ID string `xml:"id"` |
| 17 | Link []Link `xml:"link,omitempty"` |
| 18 | Updated TimeStr `xml:"updated"` |
| 19 | Author []*Person `xml:"author,omitempty"` |
| 20 | Subtitle string `xml:"subtitle,omitempty"` |
| 21 | Entry []*Entry `xml:"entry"` |
| 22 | } |
| 23 | |
| 24 | // Entry represents an Atom entry. |
| 25 | type Entry struct { |
| 26 | Title string `xml:"title"` |
| 27 | ID string `xml:"id"` |
| 28 | Link []Link `xml:"link,omitempty"` |
| 29 | Published TimeStr `xml:"published,omitempty"` |
| 30 | Updated TimeStr `xml:"updated"` |
| 31 | Author []*Person `xml:"author,omitempty"` |
| 32 | Summary *Text `xml:"summary,omitempty"` |
| 33 | Content *Text `xml:"content,omitempty"` |
| 34 | } |
| 35 | |
| 36 | // Link represents an Atom link. |
| 37 | type Link struct { |
| 38 | Rel string `xml:"rel,attr,omitempty"` |
| 39 | Href string `xml:"href,attr"` |
| 40 | Type string `xml:"type,attr,omitempty"` |
| 41 | HrefLang string `xml:"hreflang,attr,omitempty"` |
| 42 | Title string `xml:"title,attr,omitempty"` |
| 43 | Length uint `xml:"length,attr,omitempty"` |
| 44 | } |
| 45 | |
| 46 | // Person represents an Atom person. |
| 47 | type Person struct { |
| 48 | Name string `xml:"name"` |
| 49 | URI string `xml:"uri,omitempty"` |
| 50 | Email string `xml:"email,omitempty"` |
| 51 | InnerXML string `xml:",innerxml"` |
| 52 | } |
| 53 | |
| 54 | // Text represents Atom text content. |
| 55 | type Text struct { |
| 56 | Type string `xml:"type,attr"` |
| 57 | Body string `xml:",chardata"` |
| 58 | } |
| 59 | |
| 60 | type TimeStr string |
| 61 | |
| 62 | func Time(t time.Time) TimeStr { |
| 63 | return TimeStr(t.Format(time.RFC3339)) |
| 64 | } |