jsonfeed

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

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 3 Imported by: 1

README

go-jsonfeed GoDoc

jsonfeed is a Go package for parsing and constructing JSON Feeds. It explicitly supports JSON Feed Version 1.1.

To do

  • Usage examples.
  • Additional unit tests: item, hub construction; attachment validation.

Documentation

Overview

jsonfeed is a package for parsing and constructing JSON Feeds: https://jsonfeed.org/version/1.1. It explicitly supports JSON Feed Version 1.1.

Index

Constants

View Source
const Version = "https://jsonfeed.org/version/1.1"

Version is the URL of the JSON Feed spec implemented here.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	URL               string     `json:"url"`
	MIMEType          string     `json:"mime_type"`
	Title             opt.String `json:"title,omitempty"`
	SizeInBytes       opt.Int    `json:"size_in_bytes,omitempty"`
	DurationInSeconds opt.Int    `json:"duration_in_seconds,omitempty"`
}

An Attachment is an attachment on an item in a JSON Feed.

func NewAttachment

func NewAttachment(url string, mimeType string) Attachment

NewAttachment constructs a minimal Attachment.

func (Attachment) Validate

func (a Attachment) Validate() error

Validate that A represents a valid JSON Feed attachment.

type Author

type Author struct {
	Name   opt.String `json:"name,omitempty"`
	URL    opt.String `json:"url,omitempty"`
	Avatar opt.String `json:"avatar,omitempty"`
}

An Author is a JSON Feed structure identifying an Author. Feeds and Items both have single authors.

func NewAuthor

func NewAuthor() Author

NewAuthor constructs a minimal Author. Because there are no required fields for a JSON Feed author, this returns an empty Author struct.

type Feed

type Feed struct {
	Version     string     `json:"version"`
	Title       string     `json:"title"`
	HomePageURL opt.String `json:"home_page_url,omitempty"`
	FeedURL     opt.String `json:"feed_url,omitempty"`
	Description opt.String `json:"description,omitempty"`
	UserComment opt.String `json:"user_comment,omitempty"`
	NextURL     opt.String `json:"next_url,omitempty"`
	Icon        opt.String `json:"icon,omitempty"`
	Favicon     opt.String `json:"favicon,omitempty"`
	Author      *Author    `json:"author,omitempty"` // Deprecated
	Authors     []Author   `json:"authors,omitempty"`
	Language    opt.String `json:"language,omitempty"`
	Expired     opt.Bool   `json:"expired,omitempty"`
	Hubs        []Hub      `json:"hubs,omitempty"`
	Items       []Item     `json:"items"`
}

A Feed is a JSON Feed.

func NewFeed

func NewFeed(title string, items []Item) Feed

NewFeed constructs a minimal Feed.

func Parse

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

Parse constructs and validates a JSON feed from DATA.

func (Feed) ToJSON

func (f Feed) ToJSON() ([]byte, error)

ToJSON converts a Feed to its JSON representation. TODO: enforce order

func (Feed) Validate

func (f Feed) Validate() error

Validate that F represents a valid JSON feed.

type Hub

type Hub struct {
	Type string `json:"type"`
	URL  string `json:"url"`
}

A Hub describes an endpoint that can be used to subscribe to real-time notifications from the publisher of this feed.

func NewHub

func NewHub(t string, url string) Hub

NewHub constructs a minimal Hub.

func (Hub) Validate

func (h Hub) Validate() error

Validate that H represents a valid JSON Feed hub.

type IndexedMissingRequiredValueError

type IndexedMissingRequiredValueError struct {
	Index int
	// contains filtered or unexported fields
}

IndexedMissingRequiredValueError is a MissingRequiredValueError for an item at position INDEX in some iterable within the field (e.g. an array of Items or an array of Hubs).

func (IndexedMissingRequiredValueError) Error

type Item

type Item struct {
	ID            string       `json:"id"`
	URL           opt.String   `json:"url,omitempty"`
	ExternalURL   opt.String   `json:"external_url,omitempty"`
	Title         opt.String   `json:"title,omitempty"`
	ContentHTML   opt.String   `json:"content_html,omitempty"`
	ContentText   opt.String   `json:"content_text,omitempty"`
	Summary       opt.String   `json:"summary,omitempty"`
	Image         opt.String   `json:"image,omitempty"`
	BannerImage   opt.String   `json:"banner_image,omitempty"`
	DatePublished opt.String   `json:"date_published,omitempty"`
	DateModified  opt.String   `json:"date_modified,omitempty"`
	Author        *Author      `json:"author,omitempty"` // Deprecated
	Authors       []Author     `json:"authors,omitempty"`
	Tags          []string     `json:"tags,omitempty"`
	Language      opt.String   `json:"language,omitempty"`
	Attachments   []Attachment `json:"attachments,omitempty"`
}

An Item is an item in a JSON Feed.

func NewItem

func NewItem(id string) Item

NewItem constructs a minimal Item.

func (Item) Validate

func (i Item) Validate() error

Validate that I represents a valid JSON Feed item.

type MissingRequiredValueError

type MissingRequiredValueError struct {
	Structure string
	Key       string
}

A MissingRequiredValueError indicates that a required value in some JSON feed object is undefined. STRUCTURE denotes the kind of object (for example, Item or Hub). KEY is the JSON key for the missing field.

func (MissingRequiredValueError) Error

Jump to

Keyboard shortcuts

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