Skip to content

Instantly share code, notes, and snippets.

@bashbunni
Created July 12, 2024 20:06
Show Gist options
  • Save bashbunni/02956997046a8fc84317d19592486902 to your computer and use it in GitHub Desktop.
Save bashbunni/02956997046a8fc84317d19592486902 to your computer and use it in GitHub Desktop.
gofeed sorting issue
package main
import (
"sort"
"time"
"github.com/mmcdole/gofeed"
)
// RSSEntry represents a single RSS entry.
type RSSEntry struct {
Title string
Author string
Description string
URL string
PublishedAt time.Time
}
func rssFeed(url string, count int) []RSSEntry {
var r []RSSEntry
fp := gofeed.NewParser()
feed, err := fp.ParseURL(url)
if err != nil {
panic(err)
}
sort.Sort(feed)
for _, v := range feed.Items {
// fmt.Printf("%+v\n", v)
r = append(r, RSSEntry{
Title: v.Title,
Author: v.Author.Name,
Description: v.Description,
URL: v.Link,
PublishedAt: *v.PublishedParsed,
})
if len(r) == count {
break
}
}
return r
}
func main() {
rssFeed("https://charm.sh/blog/rss.xml", 10)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment