The go-rss-reader
package helps manage HTTP request for RSS feeds.
The principle is simple, it provides a Parse
function who makes the requests to the
provided URLs (concurrently for efficiency), then process each request using this
XML schema for RSS feeds.
The response is a slice of RSSItem
which is a struct that contains the information for:
- Title
- Link
- Description
- Publish Date (Defaults to
DefaultTime()
)
- Source (Defaults to the value of
url
's host )
- Source URL (Defaults to the value of
url
)
Note: url
refers to the given url in the urls slice that you should pass to
the Parse
function
The dedinition for the Parse
function and RSSItem
can be found
here
and here
respectively.
Install
go get -u github.com/dsolerh/go-rss-reader
Examples
As easy as:
package main
import (
fmt
reader "github.com/dsolerh/go-rss-reader"
)
func main() {
urls := []string{
"http://yournews.com/rss"
"http://abc.com/feed",
}
items := reader.Parse(urls...)
fmt.Println(items)
}
Use a default time function
package main
import (
fmt
reader "github.com/dsolerh/go-rss-reader"
)
func main() {
reader.DefaultTime = time.Now // this sets the time if it's not defined on the source
urls := []string{
"http://yournews.com/rss"
"http://abc.com/feed",
}
items := reader.Parse(urls...)
fmt.Println(items)
}
Exclude when no publish time is present
package main
import (
fmt
reader "github.com/dsolerh/go-rss-reader"
)
func main() {
reader.DefaultTime = nil // this makes the parse exclude the feeds if they don't include the `publish_time` field
urls := []string{
"http://yournews.com/rss"
"http://abc.com/feed",
}
items := reader.Parse(urls...)
fmt.Println(items)
}
As a result you should see a list of RSSItem
so long as the given URLs are
correct and they contain valid xml feeds.
License
Copyright (c) 2023-present Daniel Soler
Licensed under MIT License