feed

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

README

go-syndication/feed

feed

CI Go Reference

Pure-Go RSS 2.0 / Atom 1.0 / JSON Feed 1.1 parser and fetcher. CGO_ENABLED=0, zero third-party dependencies — standard library only.

The package auto-detects the source format from the bytes and normalizes RSS, Atom and JSON Feed into a single Feed type, so downstream code never has to branch on the wire format.

Install

go get github.com/go-syndication/feed

Usage

package main

import (
	"context"
	"fmt"

	"github.com/go-syndication/feed"
)

func main() {
	// Parse bytes you already have (format is auto-detected):
	f, err := feed.Parse(data)
	if err != nil {
		panic(err)
	}
	fmt.Println(f.Title)
	for _, e := range f.Entries {
		fmt.Printf("%s — %s (%s)\n", e.Title, e.Link, e.Published)
	}

	// Or fetch over HTTP (nil client uses http.DefaultClient):
	f, err = feed.Fetch(context.Background(), nil, "https://example.com/feed.xml")
	if err != nil {
		panic(err)
	}
}

API

func Parse(data []byte) (*Feed, error)
func Fetch(ctx context.Context, client *http.Client, url string) (*Feed, error)

type Feed struct {
	Title   string
	Link    string
	Entries []Entry
}

type Entry struct {
	ID        string
	Title     string
	Author    string
	Summary   string
	Content   string
	Link      string
	Published time.Time
	Media     []Enclosure
}

type Enclosure struct {
	URL  string
	Type string
}

Supported formats

  • RSS 2.0 — including dc:creator, content:encoded, <enclosure> and media:content.
  • Atom 1.0 — including rel="alternate" and rel="enclosure" links.
  • JSON Feed 1.1 — including author/authors, content_html/content_text and attachments.

License

BSD-3-Clause. See LICENSE.

Documentation

Overview

Package feed provides a dependency-free parser and fetcher for RSS 2.0, Atom 1.0 and JSON Feed 1.1 documents. It normalizes each source format into a single Feed representation.

The package uses only the Go standard library and builds with CGO disabled.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnrecognized = errors.New("feed: unrecognized format")

ErrUnrecognized is returned by Parse when the input does not look like a supported feed format.

Functions

This section is empty.

Types

type Enclosure

type Enclosure struct {
	URL  string
	Type string // MIME type, e.g. "image/jpeg"
}

Enclosure is an attached media object (RSS enclosure, media:content, Atom link rel=enclosure).

type Entry

type Entry struct {
	ID        string
	Title     string
	Author    string
	Summary   string    // short text/description (may be HTML)
	Content   string    // full content if present (may be HTML)
	Link      string    // permalink to the entry
	Published time.Time // zero if absent/unparseable
	Media     []Enclosure
}

Entry is one item/entry/post.

type Feed

type Feed struct {
	Title   string
	Link    string // site link
	Entries []Entry
}

Feed is a normalized feed regardless of source format.

func Fetch

func Fetch(ctx context.Context, client *http.Client, url string) (*Feed, error)

Fetch GETs url using client (or http.DefaultClient if nil) and parses the body into a normalized Feed.

func Parse

func Parse(data []byte) (*Feed, error)

Parse detects the format (RSS/Atom/JSONFeed) from the bytes and parses it.

Jump to

Keyboard shortcuts

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