feed.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package atom
  2. import (
  3. "encoding/json"
  4. "time"
  5. "github.com/mmcdole/gofeed/extensions"
  6. )
  7. // Feed is an Atom Feed
  8. type Feed struct {
  9. Title string `json:"title,omitempty"`
  10. ID string `json:"id,omitempty"`
  11. Updated string `json:"updated,omitempty"`
  12. UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
  13. Subtitle string `json:"subtitle,omitempty"`
  14. Links []*Link `json:"links,omitempty"`
  15. Language string `json:"language,omitempty"`
  16. Generator *Generator `json:"generator,omitempty"`
  17. Icon string `json:"icon,omitempty"`
  18. Logo string `json:"logo,omitempty"`
  19. Rights string `json:"rights,omitempty"`
  20. Contributors []*Person `json:"contributors,omitempty"`
  21. Authors []*Person `json:"authors,omitempty"`
  22. Categories []*Category `json:"categories,omitempty"`
  23. Entries []*Entry `json:"entries"`
  24. Extensions ext.Extensions `json:"extensions,omitempty"`
  25. Version string `json:"version"`
  26. }
  27. func (f Feed) String() string {
  28. json, _ := json.MarshalIndent(f, "", " ")
  29. return string(json)
  30. }
  31. // Entry is an Atom Entry
  32. type Entry struct {
  33. Title string `json:"title,omitempty"`
  34. ID string `json:"id,omitempty"`
  35. Updated string `json:"updated,omitempty"`
  36. UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
  37. Summary string `json:"summary,omitempty"`
  38. Authors []*Person `json:"authors,omitempty"`
  39. Contributors []*Person `json:"contributors,omitempty"`
  40. Categories []*Category `json:"categories,omitempty"`
  41. Links []*Link `json:"links,omitempty"`
  42. Rights string `json:"rights,omitempty"`
  43. Published string `json:"published,omitempty"`
  44. PublishedParsed *time.Time `json:"publishedParsed,omitempty"`
  45. Source *Source `json:"source,omitempty"`
  46. Content *Content `json:"content,omitempty"`
  47. Extensions ext.Extensions `json:"extensions,omitempty"`
  48. }
  49. // Category is category metadata for Feeds and Entries
  50. type Category struct {
  51. Term string `json:"term,omitempty"`
  52. Scheme string `json:"scheme,omitempty"`
  53. Label string `json:"label,omitempty"`
  54. }
  55. // Person represents a person in an Atom feed
  56. // for things like Authors, Contributors, etc
  57. type Person struct {
  58. Name string `json:"name,omitempty"`
  59. Email string `json:"email,omitempty"`
  60. URI string `json:"uri,omitempty"`
  61. }
  62. // Link is an Atom link that defines a reference
  63. // from an entry or feed to a Web resource
  64. type Link struct {
  65. Href string `json:"href,omitempty"`
  66. Hreflang string `json:"hreflang,omitempty"`
  67. Rel string `json:"rel,omitempty"`
  68. Type string `json:"type,omitempty"`
  69. Title string `json:"title,omitempty"`
  70. Length string `json:"length,omitempty"`
  71. }
  72. // Content either contains or links to the content of
  73. // the entry
  74. type Content struct {
  75. Src string `json:"src,omitempty"`
  76. Type string `json:"type,omitempty"`
  77. Value string `json:"value,omitempty"`
  78. }
  79. // Generator identifies the agent used to generate a
  80. // feed, for debugging and other purposes.
  81. type Generator struct {
  82. Value string `json:"value,omitempty"`
  83. URI string `json:"uri,omitempty"`
  84. Version string `json:"version,omitempty"`
  85. }
  86. // Source contains the feed information for another
  87. // feed if a given entry came from that feed.
  88. type Source struct {
  89. Title string `json:"title,omitempty"`
  90. ID string `json:"id,omitempty"`
  91. Updated string `json:"updated,omitempty"`
  92. UpdatedParsed *time.Time `json:"updatedParsed,omitempty"`
  93. Subtitle string `json:"subtitle,omitempty"`
  94. Links []*Link `json:"links,omitempty"`
  95. Generator *Generator `json:"generator,omitempty"`
  96. Icon string `json:"icon,omitempty"`
  97. Logo string `json:"logo,omitempty"`
  98. Rights string `json:"rights,omitempty"`
  99. Contributors []*Person `json:"contributors,omitempty"`
  100. Authors []*Person `json:"authors,omitempty"`
  101. Categories []*Category `json:"categories,omitempty"`
  102. Extensions ext.Extensions `json:"extensions,omitempty"`
  103. }