go-pkg-rss/item.go

50 lines
893 B
Go
Raw Permalink Normal View History

package feeder
2013-12-05 15:18:13 +00:00
import (
"crypto/md5"
"io"
2014-03-25 03:01:26 +00:00
"time"
2013-12-05 15:18:13 +00:00
)
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
2014-01-18 14:30:56 +00:00
2014-01-23 16:57:26 +00:00
Extensions map[string]map[string][]Extension
}
2013-12-05 15:04:00 +00:00
func (i *Item) ParsedPubDate() (time.Time, error) {
2014-03-25 03:01:26 +00:00
return parseTime(i.PubDate)
}
2013-12-05 15:04:00 +00:00
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
2013-12-05 15:18:13 +00:00
default:
h := md5.New()
io.WriteString(h, i.Description)
return string(h.Sum(nil))
2013-12-05 15:04:00 +00:00
}
}