feeds

package module
v0.0.0-...-141e1e7 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 23 Imported by: 0

README


Project license

Pull Requests welcome code with love by joshuar

Table of Contents

About

go-syndication is Go package for dealing with various feed syndication formats. It supports:

  • RSS
  • Atom
  • JSONFeed
  • Sitemaps
  • OPML
  • Various RSS/Atom extensions such as media, dublin core, itunes, and googleplay.

The package can read and write all formats. It includes built-in validation and sanitisation of elements.

Built With

Getting Started

Prerequisites

TBA.

Installation

TBA.

Usage

TBA.

Roadmap

See the open issues for a list of proposed features (and known issues).

Support

Reach out to the maintainer at one of the following places:

Project assistance

If you want to say thank you or/and support active development of go-syndication:

  • Add a GitHub Star to the project.
  • Tweet about the go-syndication.
  • Write interesting articles about the project on Dev.to, Medium or your personal blog.

Together, we can make go-syndication better!

Contributing

First off, thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are greatly appreciated.

Please read our contribution guidelines, and thank you for being involved!

Authors & contributors

The original setup of this repository is by joshuar.

For a full list of all authors and contributors, see the contributors page.

Security

go-syndication follows good practices of security, but 100% security cannot be assured. go-syndication is provided "as is" without any warranty. Use at your own risk.

For more information and to report security issues, please refer to our security documentation.

License

This project is licensed under the MIT license.

See LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrParseBytes indicates an error occurred trying to parse a byte array as a feed.
	ErrParseBytes = errors.New("unable to parse bytes as feed")
	// ErrParseURL indicates an error occurred trying to parse a URL as a feed.
	ErrParseURL = errors.New("unable to parse URL as feed")
	// ErrUnsupportedFormat indicates that feed format is not known and cannot be parsed.
	ErrUnsupportedFormat = errors.New("unsupported feed format")
)
View Source
var ErrUnmarshal = errors.New("unmarshaling object failed")

ErrUnmarshal indicates an error occurred trying to unmarshal data into a given feed object.

Functions

func Decode

func Decode[T any](namespace string, b []byte) (T, error)

Decode will decode the byte array into the given type T, and assign values without a namespace with the given namespace.

func DiscoverFeedURL

func DiscoverFeedURL(sourceURL *url.URL, content []byte) (string, error)

DiscoverFeedURL attempts to find a feed URL within a HTML page.

There are a couple of "canonical" places the feed URL is located. Firstly, as per the RSS spec, look for a link element with rel="alternate" and type="application/rss+xml". Secondly, check for a link element with a URL that ends with feed, rss or atom, which would indicate a feed URL.

func DiscoverPageImage

func DiscoverPageImage(pageURL string, timeout time.Duration) (*types.ImageInfo, error)

DiscoverPageImage attempts to find a suitable image to use for a page.

func Encode

func Encode[T any](feed T) ([]byte, error)

Encode will encode the given type T into a byte array.

Types

type Feed

type Feed struct {
	types.FeedSource `json:"source"`

	SourceType SourceType `json:"type"`
}

Feed represents any feed type containing a number of items.

func NewFeedFromBytes

func NewFeedFromBytes[T any](data []byte, options ...ParseOption) (*Feed, error)

NewFeedFromBytes will create a new Feed of the given type from the given byte array.

func NewFeedFromSource

func NewFeedFromSource[T types.FeedSource](source T, options ...ParseOption) *Feed

NewFeedFromSource will create a new Feed from the given source that satisfies the FeedSource interface. This can be used to create a Feed from an existing rss.RSS or atom.Feed object.

func NewFeedFromURL

func NewFeedFromURL(ctx context.Context, feedURL string, options ...ParseOption) (*Feed, error)

NewFeedFromURL attempts to parse the given URL as a feed source.

func (*Feed) GetItems

func (f *Feed) GetItems() []Item

GetItems retrieves a slice of Item for the Feed.

func (*Feed) UnmarshalJSON

func (f *Feed) UnmarshalJSON(v []byte) error

UnmarshalJSON handles unmarshaling of a Feed from JSON.

type HTTPError

type HTTPError struct {
	Code    int
	Message string
}

func (HTTPError) Error

func (e HTTPError) Error() string

type Item

type Item struct {
	types.ItemSource `json:"source"`

	SourceType SourceType `json:"type"`
	FeedTitle  string     `json:"feed_title"`
}

Item represents a single item or entry (or article) in a feed.

func (*Item) UnmarshalJSON

func (i *Item) UnmarshalJSON(v []byte) error

UnmarshalJSON handles unmarshaling of an Item from JSON.

type ParseOption

type ParseOption func(*ParserOptions)

func PerformValidation

func PerformValidation(value bool) ParseOption

PerformValidation option controls whether validation will be performed after the feed data has been parsed. This allows a feed that doesn't strictly pass its format specification to be returned.

func WithClient

func WithClient(client *resty.Client) ParseOption

WithClient option allows using a custom client for any network requests to fetch feed resources.

type ParserOptions

type ParserOptions struct {
	// contains filtered or unexported fields
}

type SourceType

type SourceType string

SourceType is a string constant that indicates the underlying source data type of a Feed/Item object. This is mainly used when unmarshaling from JSON where the JSON structure of the source types can be ambiguous.

const (
	// TypeRSS indicates the source data was from an RSS feed.
	TypeRSS SourceType = "RSS"
	// TypeAtom indicates the source data was from an Atom feed.
	TypeAtom SourceType = "Atom"
	// TypeJSONFeed indicates the source data was from a JSONFeed feed.
	TypeJSONFeed SourceType = "JSONFeed"
)

Directories

Path Synopsis
Package atom provides primitives to interact with the openapi HTTP API.
Package atom provides primitives to interact with the openapi HTTP API.
extensions
dc
Package dc provides primitives to interact with the openapi HTTP API.
Package dc provides primitives to interact with the openapi HTTP API.
googleplay
Package googleplay provides primitives to interact with the openapi HTTP API.
Package googleplay provides primitives to interact with the openapi HTTP API.
itunes
Package itunes provides primitives to interact with the openapi HTTP API.
Package itunes provides primitives to interact with the openapi HTTP API.
media
Package media provides primitives to interact with the openapi HTTP API.
Package media provides primitives to interact with the openapi HTTP API.
rss
Package rss provides primitives to interact with the openapi HTTP API.
Package rss provides primitives to interact with the openapi HTTP API.
Package jsonfeed provides primitives to interact with the openapi HTTP API.
Package jsonfeed provides primitives to interact with the openapi HTTP API.
Package opengraph provides primitives to interact with the openapi HTTP API.
Package opengraph provides primitives to interact with the openapi HTTP API.
Package opml provides primitives to interact with the openapi HTTP API.
Package opml provides primitives to interact with the openapi HTTP API.
Package rss provides primitives to interact with the openapi HTTP API.
Package rss provides primitives to interact with the openapi HTTP API.
Package schema contains the OpenAPI schema definitions for go-syndication.
Package schema contains the OpenAPI schema definitions for go-syndication.
Package sitemap provides primitives to interact with the openapi HTTP API.
Package sitemap provides primitives to interact with the openapi HTTP API.
Package types provides primitives to interact with the openapi HTTP API.
Package types provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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