Rename RSS parser getters
This commit is contained in:
parent
f76093690c
commit
e2d02bac5a
1 changed files with 36 additions and 36 deletions
|
@ -43,22 +43,6 @@ type rssCommentLink struct {
|
||||||
Data string `xml:",chardata"`
|
Data string `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type rssItem struct {
|
|
||||||
GUID string `xml:"guid"`
|
|
||||||
Title string `xml:"title"`
|
|
||||||
Links []rssLink `xml:"link"`
|
|
||||||
OriginalLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"`
|
|
||||||
CommentLinks []rssCommentLink `xml:"comments"`
|
|
||||||
Description string `xml:"description"`
|
|
||||||
Content string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"`
|
|
||||||
PubDate string `xml:"pubDate"`
|
|
||||||
Date string `xml:"http://purl.org/dc/elements/1.1/ date"`
|
|
||||||
Authors []rssAuthor `xml:"author"`
|
|
||||||
Creator string `xml:"http://purl.org/dc/elements/1.1/ creator"`
|
|
||||||
Enclosures []rssEnclosure `xml:"enclosure"`
|
|
||||||
OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type rssAuthor struct {
|
type rssAuthor struct {
|
||||||
XMLName xml.Name
|
XMLName xml.Name
|
||||||
Data string `xml:",chardata"`
|
Data string `xml:",chardata"`
|
||||||
|
@ -72,7 +56,23 @@ type rssEnclosure struct {
|
||||||
Length string `xml:"length,attr"`
|
Length string `xml:"length,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssFeed) GetSiteURL() string {
|
type rssItem struct {
|
||||||
|
GUID string `xml:"guid"`
|
||||||
|
Title string `xml:"title"`
|
||||||
|
Links []rssLink `xml:"link"`
|
||||||
|
OriginalLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origLink"`
|
||||||
|
CommentLinks []rssCommentLink `xml:"comments"`
|
||||||
|
Description string `xml:"description"`
|
||||||
|
EncodedContent string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"`
|
||||||
|
PubDate string `xml:"pubDate"`
|
||||||
|
Date string `xml:"http://purl.org/dc/elements/1.1/ date"`
|
||||||
|
Authors []rssAuthor `xml:"author"`
|
||||||
|
Creator string `xml:"http://purl.org/dc/elements/1.1/ creator"`
|
||||||
|
EnclosureLinks []rssEnclosure `xml:"enclosure"`
|
||||||
|
OrigEnclosureLink string `xml:"http://rssnamespace.org/feedburner/ext/1.0 origEnclosureLink"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *rssFeed) SiteURL() string {
|
||||||
for _, element := range r.Links {
|
for _, element := range r.Links {
|
||||||
if element.XMLName.Space == "" {
|
if element.XMLName.Space == "" {
|
||||||
return strings.TrimSpace(element.Data)
|
return strings.TrimSpace(element.Data)
|
||||||
|
@ -82,7 +82,7 @@ func (r *rssFeed) GetSiteURL() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssFeed) GetFeedURL() string {
|
func (r *rssFeed) FeedURL() string {
|
||||||
for _, element := range r.Links {
|
for _, element := range r.Links {
|
||||||
if element.XMLName.Space == "http://www.w3.org/2005/Atom" {
|
if element.XMLName.Space == "http://www.w3.org/2005/Atom" {
|
||||||
return strings.TrimSpace(element.Href)
|
return strings.TrimSpace(element.Href)
|
||||||
|
@ -94,8 +94,8 @@ func (r *rssFeed) GetFeedURL() string {
|
||||||
|
|
||||||
func (r *rssFeed) Transform() *model.Feed {
|
func (r *rssFeed) Transform() *model.Feed {
|
||||||
feed := new(model.Feed)
|
feed := new(model.Feed)
|
||||||
feed.SiteURL = r.GetSiteURL()
|
feed.SiteURL = r.SiteURL()
|
||||||
feed.FeedURL = r.GetFeedURL()
|
feed.FeedURL = r.FeedURL()
|
||||||
feed.Title = strings.TrimSpace(r.Title)
|
feed.Title = strings.TrimSpace(r.Title)
|
||||||
|
|
||||||
if feed.Title == "" {
|
if feed.Title == "" {
|
||||||
|
@ -129,7 +129,7 @@ func (r *rssFeed) Transform() *model.Feed {
|
||||||
return feed
|
return feed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssItem) GetDate() time.Time {
|
func (r *rssItem) PublishedDate() time.Time {
|
||||||
value := r.PubDate
|
value := r.PubDate
|
||||||
if r.Date != "" {
|
if r.Date != "" {
|
||||||
value = r.Date
|
value = r.Date
|
||||||
|
@ -148,7 +148,7 @@ func (r *rssItem) GetDate() time.Time {
|
||||||
return time.Now()
|
return time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssItem) GetAuthor() string {
|
func (r *rssItem) Author() string {
|
||||||
for _, element := range r.Authors {
|
for _, element := range r.Authors {
|
||||||
if element.Name != "" {
|
if element.Name != "" {
|
||||||
return element.Name
|
return element.Name
|
||||||
|
@ -162,8 +162,8 @@ func (r *rssItem) GetAuthor() string {
|
||||||
return r.Creator
|
return r.Creator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssItem) GetHash() string {
|
func (r *rssItem) Hash() string {
|
||||||
for _, value := range []string{r.GUID, r.GetURL()} {
|
for _, value := range []string{r.GUID, r.URL()} {
|
||||||
if value != "" {
|
if value != "" {
|
||||||
return crypto.Hash(value)
|
return crypto.Hash(value)
|
||||||
}
|
}
|
||||||
|
@ -172,15 +172,15 @@ func (r *rssItem) GetHash() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssItem) GetContent() string {
|
func (r *rssItem) Content() string {
|
||||||
if r.Content != "" {
|
if r.EncodedContent != "" {
|
||||||
return r.Content
|
return r.EncodedContent
|
||||||
}
|
}
|
||||||
|
|
||||||
return r.Description
|
return r.Description
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssItem) GetURL() string {
|
func (r *rssItem) URL() string {
|
||||||
if r.OriginalLink != "" {
|
if r.OriginalLink != "" {
|
||||||
return r.OriginalLink
|
return r.OriginalLink
|
||||||
}
|
}
|
||||||
|
@ -198,10 +198,10 @@ func (r *rssItem) GetURL() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rssItem) GetEnclosures() model.EnclosureList {
|
func (r *rssItem) Enclosures() model.EnclosureList {
|
||||||
enclosures := make(model.EnclosureList, 0)
|
enclosures := make(model.EnclosureList, 0)
|
||||||
|
|
||||||
for _, enclosure := range r.Enclosures {
|
for _, enclosure := range r.EnclosureLinks {
|
||||||
length, _ := strconv.ParseInt(enclosure.Length, 10, 0)
|
length, _ := strconv.ParseInt(enclosure.Length, 10, 0)
|
||||||
enclosureURL := enclosure.URL
|
enclosureURL := enclosure.URL
|
||||||
|
|
||||||
|
@ -234,14 +234,14 @@ func (r *rssItem) CommentsURL() string {
|
||||||
|
|
||||||
func (r *rssItem) Transform() *model.Entry {
|
func (r *rssItem) Transform() *model.Entry {
|
||||||
entry := new(model.Entry)
|
entry := new(model.Entry)
|
||||||
entry.URL = r.GetURL()
|
entry.URL = r.URL()
|
||||||
entry.CommentsURL = r.CommentsURL()
|
entry.CommentsURL = r.CommentsURL()
|
||||||
entry.Date = r.GetDate()
|
entry.Date = r.PublishedDate()
|
||||||
entry.Author = r.GetAuthor()
|
entry.Author = r.Author()
|
||||||
entry.Hash = r.GetHash()
|
entry.Hash = r.Hash()
|
||||||
entry.Content = r.GetContent()
|
entry.Content = r.Content()
|
||||||
entry.Title = strings.TrimSpace(r.Title)
|
entry.Title = strings.TrimSpace(r.Title)
|
||||||
entry.Enclosures = r.GetEnclosures()
|
entry.Enclosures = r.Enclosures()
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue