rss

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2025 License: MIT Imports: 5 Imported by: 0

README

RSS Library

A Go library for parsing RSS, Atom, and JSON feeds with a unified interface.

Features

  • Unified API: Parse RSS, Atom, and JSON Feed formats using a single Parse() function
  • Automatic Format Detection: Automatically detects the feed format
  • No External Dependencies: Pure Go implementation
  • Comprehensive Testing: Full test coverage for all supported formats including real-world feeds

Supported Formats

  • RSS 2.0: Full support for RSS 2.0 specification
  • Atom 1.0: Complete Atom 1.0 parsing
  • JSON Feed 1.1: Support for JSON Feed version 1.1

Installation

go get git.quad4.io/Go-Libs/RSS

Usage

package main

import (
    "fmt"
    "log"

    "git.quad4.io/Go-Libs/RSS"
)

func main() {
    // Parse any feed format (RSS, Atom, or JSON Feed)
    feed, err := rss.Parse(feedData)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("Feed Title:", feed.Title)
    fmt.Println("Feed Description:", feed.Description)

    for _, item := range feed.Items {
        fmt.Println("Item:", item.Title)
        fmt.Println("Link:", item.Link)
        fmt.Println("Published:", item.Published)
    }
}

API Reference

Types
Feed

Represents a parsed feed with unified interface across all formats.

type Feed struct {
    Title       string     // Feed title
    Description string     // Feed description
    Link        string     // Link to feed's website
    FeedURL     string     // URL of the feed itself
    Language    string     // Feed language
    Author      *Person    // Feed author
    Published   *time.Time // Publication date
    Updated     *time.Time // Last updated date
    Items       []*Item    // Feed items
}
Item

Represents an individual item/entry in a feed.

type Item struct {
    Title       string       // Item title
    Description string       // Item content/description
    Link        string       // Link to item
    GUID        string       // Unique identifier
    Published   *time.Time   // Publication date
    Updated     *time.Time   // Last updated date
    Author      *Person      // Item author
    Categories  []string     // Tags/categories
    Enclosures  []*Enclosure // Attachments/media
}
Person

Represents a person (author, contributor).

type Person struct {
    Name  string // Person's name
    Email string // Email address
    URI   string // Website/profile URL
}
Enclosure

Represents an attachment or media file.

type Enclosure struct {
    URL    string // File URL
    Length int64  // File size in bytes
    Type   string // MIME type
}
Functions
Parse(data []byte) (*Feed, error)

Parses feed data and returns a unified Feed structure. Automatically detects the format (RSS, Atom, or JSON Feed).

Examples

See the examples/ directory for complete usage examples demonstrating parsing of RSS, Atom, and JSON feeds.

Running Tests

go test

Running Examples

The example demonstrates fetching and parsing real RSS feeds from popular websites:

cd examples
go run example.go

This will fetch live feeds from Hacker News, Ars Technica, and The Verge, showing how the unified API works with real-world data.

License

MIT License - see LICENSE file for details.

Documentation

Overview

Package rss provides parsing for RSS, Atom, and JSON Feed formats.

This package allows you to parse RSS feeds from various sources and formats into a unified interface. It supports RSS 2.0, Atom 1.0, and JSON Feed 1.1 formats.

Example usage:

import "git.quad4.io/Go-Libs/RSS"

feed, err := rss.Parse([]byte(feedData))
if err != nil {
	// handle error
}
fmt.Println("Feed title:", feed.Title)
for _, item := range feed.Items {
	fmt.Println("Item:", item.Title)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enclosure

type Enclosure struct {
	// URL of the enclosure
	URL string
	// Length in bytes
	Length int64
	// MIME type
	Type string
}

Enclosure represents an attachment or media file associated with an item.

type Feed

type Feed struct {
	// Title of the feed
	Title string
	// Description of the feed
	Description string
	// Link to the feed's website
	Link string
	// FeedURL is the URL of the feed itself
	FeedURL string
	// Language of the feed
	Language string
	// Author of the feed
	Author *Person
	// Published date of the feed
	Published *time.Time
	// Updated date of the feed (for feeds that support it)
	Updated *time.Time
	// Items in the feed
	Items []*Item
}

Feed represents a parsed RSS feed with a unified interface across all formats.

func Parse

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

Parse attempts to parse feed data in RSS, Atom, or JSON Feed format. It automatically detects the format and returns a unified Feed structure.

type Item

type Item struct {
	// Title of the item
	Title string
	// Description/Content of the item
	Description string
	// Link to the item
	Link string
	// GUID uniquely identifies the item
	GUID string
	// Published date of the item
	Published *time.Time
	// Updated date of the item (for items that support it)
	Updated *time.Time
	// Author of the item
	Author *Person
	// Categories/Tags for the item
	Categories []string
	// Enclosures (attachments, media)
	Enclosures []*Enclosure
}

Item represents an individual item/entry in a feed.

type Person

type Person struct {
	// Name of the person
	Name string
	// Email address
	Email string
	// URI (website, profile, etc.)
	URI string
}

Person represents a person (author, contributor, etc.)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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