feed.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package gofeed
  2. import (
  3. "encoding/json"
  4. "time"
  5. "github.com/mmcdole/gofeed/extensions"
  6. )
  7. // Feed is the universal Feed type that atom.Feed
  8. // and rss.Feed gets translated to. It represents
  9. // a web feed.
  10. type Feed struct {
  11. Title string `json:"title,omitempty"`
  12. Description string `json:"description,omitempty"`
  13. Link string `json:"link,omitempty"`
  14. FeedLink string `json:"feedLink,omitempty"`
  15. Updated string `json:"updated,omitempty"`
  16. UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
  17. Published string `json:"published,omitempty"`
  18. PublishedParsed *time.Time `json:"publishedParsed,omitempty"`
  19. Author *Person `json:"author,omitempty"`
  20. Language string `json:"language,omitempty"`
  21. Image *Image `json:"image,omitempty"`
  22. Copyright string `json:"copyright,omitempty"`
  23. Generator string `json:"generator,omitempty"`
  24. Categories []string `json:"categories,omitempty"`
  25. DublinCoreExt *ext.DublinCoreExtension `json:"dcExt,omitempty"`
  26. ITunesExt *ext.ITunesFeedExtension `json:"itunesExt,omitempty"`
  27. Extensions ext.Extensions `json:"extensions,omitempty"`
  28. Custom map[string]string `json:"custom,omitempty"`
  29. Items []*Item `json:"items"`
  30. FeedType string `json:"feedType"`
  31. FeedVersion string `json:"feedVersion"`
  32. }
  33. func (f Feed) String() string {
  34. json, _ := json.MarshalIndent(f, "", " ")
  35. return string(json)
  36. }
  37. // Item is the universal Item type that atom.Entry
  38. // and rss.Item gets translated to. It represents
  39. // a single entry in a given feed.
  40. type Item struct {
  41. Title string `json:"title,omitempty"`
  42. Description string `json:"description,omitempty"`
  43. Content string `json:"content,omitempty"`
  44. Link string `json:"link,omitempty"`
  45. Updated string `json:"updated,omitempty"`
  46. UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
  47. Published string `json:"published,omitempty"`
  48. PublishedParsed *time.Time `json:"publishedParsed,omitempty"`
  49. Author *Person `json:"author,omitempty"`
  50. GUID string `json:"guid,omitempty"`
  51. Image *Image `json:"image,omitempty"`
  52. Categories []string `json:"categories,omitempty"`
  53. Enclosures []*Enclosure `json:"enclosures,omitempty"`
  54. DublinCoreExt *ext.DublinCoreExtension `json:"dcExt,omitempty"`
  55. ITunesExt *ext.ITunesItemExtension `json:"itunesExt,omitempty"`
  56. Extensions ext.Extensions `json:"extensions,omitempty"`
  57. Custom map[string]string `json:"custom,omitempty"`
  58. }
  59. // Person is an individual specified in a feed
  60. // (e.g. an author)
  61. type Person struct {
  62. Name string `json:"name,omitempty"`
  63. Email string `json:"email,omitempty"`
  64. }
  65. // Image is an image that is the artwork for a given
  66. // feed or item.
  67. type Image struct {
  68. URL string `json:"url,omitempty"`
  69. Title string `json:"title,omitempty"`
  70. }
  71. // Enclosure is a file associated with a given Item.
  72. type Enclosure struct {
  73. URL string `json:"url,omitempty"`
  74. Length string `json:"length,omitempty"`
  75. Type string `json:"type,omitempty"`
  76. }