45 lines
804 B
Go
45 lines
804 B
Go
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 time.Time
|
|
Source *Source
|
|
|
|
// Atom specific fields
|
|
Id string
|
|
Generator *Generator
|
|
Contributors []string
|
|
Content *Content
|
|
|
|
Extensions map[string]map[string][]Extension
|
|
}
|
|
|
|
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 && !i.PubDate.IsZero():
|
|
return i.Title + i.PubDate.String()
|
|
default:
|
|
h := md5.New()
|
|
io.WriteString(h, i.Description)
|
|
return string(h.Sum(nil))
|
|
}
|
|
}
|