rssreader

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 7 Imported by: 0

README

go-rss-reader

tests

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:

  1. Title
  2. Link
  3. Description
  4. Publish Date (Defaults to DefaultTime())
  5. Source (Defaults to the value of url's host )
  6. 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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultTimeFunc added in v0.2.0

type DefaultTimeFunc func() time.Time
var DefaultTime DefaultTimeFunc = func() time.Time { return time.Time{} }

type RSSItem

type RSSItem struct {
	Title       string    // Defines the title of the item
	Source      string    // Specifies a third-party source for the item
	SourceURL   string    // Specifies the link to the source
	Link        string    // Defines the hyperlink to the item
	PublishDate time.Time // Defines the last-publication date for the item
	Description string    // Describes the item
}

RSSItem is the representation of an item retrieved from an RSS feed

func Parse

func Parse(urls ...string) []RSSItem

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL