atom.go (1537B)
1 // Package atom implements decoding encoding of Atom feeds as 2 // specified in RFC 4287. 3 package atom 4 5 import ( 6 "encoding/xml" 7 "time" 8 ) 9 10 // MediaType is Atom's IANA media type. 11 const MediaType = "application/atom+xml" 12 13 type Feed struct { 14 ID string `xml:"id"` 15 Title string `xml:"title"` 16 Updated time.Time `xml:"updated"` 17 Author *Author `xml:"author,omitempty"` 18 Link []Link `xml:"link,omitempty"` 19 Subtitle string `xml:"subtitle,omitempty"` 20 Entries []Entry `xml:"entry"` 21 } 22 23 var rootElement = xml.StartElement{ 24 Name: xml.Name{ 25 Space: "http://www.w3.org/2005/Atom", 26 Local: "feed", 27 }, 28 } 29 30 type alias Feed 31 32 func (f *Feed) MarshalXML(e *xml.Encoder, start xml.StartElement) error { 33 return e.EncodeElement(alias(*f), rootElement) 34 } 35 36 func (f *Feed) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { 37 return d.DecodeElement((*alias)(f), &rootElement) 38 } 39 40 type Author struct { 41 Name string `xml:"name"` 42 URI string `xml:"uri,omitempty"` 43 Email string `xml:"email,omitempty"` 44 } 45 46 type Entry struct { 47 ID string `xml:"id"` 48 Title string `xml:"title"` 49 Updated time.Time `xml:"updated,omitempty"` 50 Author *Author `xml:"author,omitempty"` 51 Links []Link `xml:"link"` 52 Summary string `xml:"summary,omitempty"` 53 Content []byte `xml:"content,omitempty"` 54 Published *time.Time `xml:"published,omitempty"` 55 } 56 57 type Link struct { 58 HRef string `xml:"href,attr,omitempty"` 59 Rel string `xml:"rel,attr,omitempty"` 60 Type string `xml:"type,attr,omitempty"` 61 }