-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.go
More file actions
114 lines (96 loc) · 3.03 KB
/
feed.go
File metadata and controls
114 lines (96 loc) · 3.03 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package rss
import (
"fmt"
"time"
)
type Feed struct {
Title string `xml:"title"`
Link string `xml:"link"`
Description string `xml:"description"`
Image *Image `xml:"image"`
Language string `xml:"language,omitempty"`
Date Date `xml:"pubDate"`
Category []string `xml:"category"`
Generator string `xml:"generator,omitempty"`
Ttl int `xml:"ttl,omitempty"`
Items []*Item `xml:"item"`
}
type Image struct {
Url string `xml:"url"`
Title string `xml:"title"`
Link string `xml:"link"`
Width int `xml:"width,omitempty"`
Height int `xml:"height,omitempty"`
}
type Date struct {
time.Time
}
type Item struct {
Title string `xml:"title,omitempty"`
Guid Guid `xml:"guid"`
Link string `xml:"link,omitempty"`
Description string `xml:"description,omitempty"`
Enclosure []*Enclosure `xml:"enclosure"`
MediaContent []*MediaContent `xml:"http://search.yahoo.com/mrss/ content"`
MediaGroup []*MediaGroup `xml:"http://search.yahoo.com/mrss/ group"`
Comments string `xml:"comments,omitempty"`
Date Date `xml:"pubDate"`
Author string `xml:"author,omitempty"`
Category []string `xml:"category"`
}
type Guid struct {
Id string `xml:",chardata"`
IsPermaLink *bool `xml:"isPermaLink,attr,omitempty"`
}
type Enclosure struct {
Url string `xml:"url,attr"`
Type string `xml:"type,attr"`
Length int `xml:"length,attr"`
}
type MediaGroup struct {
Title *MediaDescription `xml:"title"`
Thumbnail *MediaThumbnail `xml:"thumbnail"`
Content *MediaContent `xml:"content"`
Description *MediaDescription `xml:"description"`
Keywords string `xml:"keywords,omitempty"`
}
type MediaContent struct {
Title *MediaDescription `xml:"title"`
Thumbnail *MediaThumbnail `xml:"thumbnail"`
Url string `xml:"url,attr,omitempty"`
Medium string `xml:"medium,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
Expression string `xml:"expression,attr,omitempty"`
Width int `xml:"width,attr,omitempty"`
Height int `xml:"height,attr,omitempty"`
IsDefault bool `xml:"isDefault,attr,omitempty"`
Description *MediaDescription `xml:"description"`
Keywords string `xml:"keywords,omitempty"`
}
type MediaDescription struct {
Text string `xml:",chardata"`
Type string `xml:"type,attr,omitempty"`
}
type MediaThumbnail struct {
Url string `xml:"url,attr,omitempty"`
Width int `xml:"width,attr,omitempty"`
Height int `xml:"height,attr,omitempty"`
}
func (item *Item) HasCategory(category string) bool {
for _, itemCategory := range item.Category {
if itemCategory == category {
return true
}
}
return false
}
func (feed *Feed) String() string {
if feed == nil {
return fmt.Sprintf("%#v", feed)
}
xml, err := Generate(feed)
if err == nil {
return string(xml)
}
return fmt.Sprintf("XML generation error: %s. Go representation: %#v", err, feed)
}