rss

package module
v0.0.0-...-fde60d0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 8 Imported by: 0

README

go-rss

Package rss implements encoders and decoders for the RSS (Really Simple Syndication) web-feed format, for the Go programming language.

Package rss is meant to be used with the Go built-in "encoding/xml" package.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-rss

GoDoc

Examples

To unmarshal RSS data to rss.RSS2 in Go, you can do something similar to the following:

import (
	"encoding/xml"

	"github.com/reiver/go-rss"
}

// ...

var rss2 rss.RSS2

err := xml.Unmarshal(p, &rss2)

To make an HTTP request to a URL for RSS and then unmarshal it, you can do something similar to the following:

import (
	"github.com/reiver/go-rss"
}

// ...

url := "https://mastodon.social/tags/fedidev.rss"

var rss2 rss.RSS2

err := rss.HTTPGetAndUnmarshal(url, &rss2)

Installation

To install package rss do the following:

GOPROXY=direct go get github.com/reiver/go-rss

Author

Package rss was written by Charles Iliya Krempeaux

Documentation

Index

Constants

View Source
const (
	ErrNilReceiver       = erorr.Error("nil receiver")
	ErrPubDateUnparsable = erorr.Error("RSS pubDate unparsable")
)
View Source
const MediaType = "application/rss+xml"

MediaType is the RSS (specific) media-type.

One might want to use it with the HTTP "Accept" request header, or the HTTP "Content-Type" response header.

Note that, prior to the adoption of the "application/rss+xml", non-RSS specific media-types were often used with RSS. For example:

  • "application/xml"
  • "text/xml"
  • "text/plain"

It is NOT recommended to use these other media-types with RSS. And to instead use "application/rss+xml".

The rss.MediaType constant exists to make that easier.

Variables

This section is empty.

Functions

func HTTPGet

func HTTPGet(url string) ([]byte, error)

HTTPGet makes an HTTP GET request to a URL with the HTTP "Accept" request header set to "application/rss+xml" (the RSS media-type).

Example usage:

bytes, err := rss.HTTPGet(url)

See also: HTTPGetAndUnmarshal

func HTTPGetAndUnmarshal

func HTTPGetAndUnmarshal(url string, dst any) error

HTTPGetAndMarshal makes an HTTP GET request to a URL with the HTTP "Accept" request header set to "application/rss+xml" (the RSS media-type), and then unmarshals the body of the resulting HTTP response into RSS.

Example usage:

var rss2 rss.RSS2
err := rss.HTTPGetAndUnmarshal(url, &rss2)

See also: HTTPGet

Types

type Channel

type Channel struct {
	Title       string `xml:"title"`
	Link        string `xml:"link"`
	Description string `xml:"description"`
	Items       []Item `xml:"item"`
}

type Description

type Description struct {
	Value string `xml:",chardata"`
}

func (*Description) HTML

func (receiver *Description) HTML() string

type GUID

type GUID struct {
	IsPermaLink bool   `xml:"isPermaLink,attr"`
	Value       string `xml:",chardata"`
}

type Item

type Item struct {
	Author      string      `xml:"author"`
	Categories  []string    `xml:"category"`
	Description Description `xml:"description"`
	GUID        GUID        `xml:"guid"`
	Link        string      `xml:"link"`
	PubDate     PubDate     `xml:"pubDate"`
	Title       string      `xml:"title"`
}

type PubDate

type PubDate struct {
	Value string `xml:",chardata"`
}

func (PubDate) Parse

func (receiver PubDate) Parse() (time.Time, error)

type RSS2

type RSS2 struct {
	XMLName xml.Name `xml:"rss"`
	Channel Channel  `xml:"channel"`
}

RSS2 represents a full RSS 2.0 XML document.

Jump to

Keyboard shortcuts

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