forked from emmaly/go-pkg-rss
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
item.go
49 lines (43 loc) · 893 Bytes
/
item.go
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
package feeder
import (
"crypto/md5"
"io"
"time"
)
type Item struct {
// RSS and Shared fields
Title string
Links []*Link
Description string
Author Author
Categories []*Category
Comments string
Enclosures []*Enclosure
Guid *string
PubDate string
Source *Source
// Atom specific fields
Id string
Generator *Generator
Contributors []string
Content *Content
Updated string
Extensions map[string]map[string][]Extension
}
func (i *Item) ParsedPubDate() (time.Time, error) {
return parseTime(i.PubDate)
}
func (i *Item) Key() string {
switch {
case i.Guid != nil && len(*i.Guid) != 0:
return *i.Guid
case len(i.Id) != 0:
return i.Id
case len(i.Title) > 0 && len(i.PubDate) > 0:
return i.Title + i.PubDate
default:
h := md5.New()
io.WriteString(h, i.Description)
return string(h.Sum(nil))
}
}