jsonfeed

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

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

Go to latest
Published: Aug 20, 2018 License: MIT Imports: 8 Imported by: 0

README

Go JSON Feed

Basic implementation of the JSON Feed specs for go.

Usage

First install the package with go get github.com/IanS5/go-jsonfeed.

To get a feed use feed, err := jsonfeed.OpenFeed(feed_url).

Feeds implement the http.Handler interface, so to serve a feed just use http.Handle('/my/feed/url', feed).

Feeds can write data with the JSONFeed.Write(io.Writer) method and read data with the JSONFeed.Read(io.Reader) method.

All names in the JSONFeed struct have the same words as the json fields, but in CammelCase with the First letter capitalized, URL and ID are always all uppercase. home_page_url = HomePageURL

Example

A more complicated example can be found in examples/network.go

package main

import (
    "net/http"
    "github.com/IanS5/go-jsonfeed"
)
func main () {
    feed,err := jsonfeed.OpenFeed("https://jsonfeed.org/feed.json")
    if err != nil {
        panic(err)
    }
    log.Fatal(http.ListenAndServe(":8080",feed));
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	URL               string `json:"url,omitempty" feed:"required"`
	MimeType          string `json:"mime_type,omitempty" feed:"required"`
	Title             string `json:"title,omitempty" feed:"optional"`
	SizeInBytes       int64  `json:"size_in_bytes,omitempty" feed:"optional"`
	DurationInSeconds int64  `json:"duration_in_seconds,omitempty" feed:"optional"`
}

Attachment a list of resources related to a file

func NewAudio

func NewAudio(title string, url string) (at *Attachment)

NewAudio creates a new adio attachment

func NewImage

func NewImage(title string, url string) (at *Attachment)

NewImage creates a new image attachment

func NewVideo

func NewVideo(title string, url string) (at *Attachment)

NewVideo creates a new video attachment

type Author

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

Author Basic information on the feed's author

type Hub

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

Hub An endpoint that can be used to subscibe to the real-time notifications from the publisher of a feed

type Item

type Item struct {
	ID            string        `json:"id,omitempty" feed:"required"`
	URL           string        `json:"url,omitempty" feed:"optional"`
	ExternalURL   string        `json:"external_url,omitempty" feed:"optional"`
	Title         string        `json:"title,omitempty" feed:"optional"`
	ContentHTML   string        `json:"content_html,omitempty" feed:"optional"`
	ContentText   string        `json:"content_text,omitempty" feed:"optional"`
	Summary       string        `json:"summary,omitempty" feed:"optional"`
	Image         string        `json:"image,omitempty" feed:"optional"`
	BannerImage   string        `json:"banner_image,omitempty" feed:"optional"`
	DatePublished time.Time     `json:"date_published,omitempty" feed:"optional"`
	DateModified  time.Time     `json:"date_modified,omitempty" feed:"optional"`
	Author        Author        `json:"author,omitempty" feed:"optional"`
	Tags          []string      `json:"tags,omitempty" feed:"optional"`
	Attachments   []*Attachment `json:"attachments,omitempty" feed:"optional"`
}

Item a single item in a feed

type JSONFeed

type JSONFeed struct {
	Version     string   `json:"version,omitempty" feed:"required"`
	Title       string   `json:"title,omitempty" feed:"required"`
	HomePageURL string   `json:"home_page_url,omitempty" feed:"optional"`
	FeedURL     string   `json:"feed_url,omitempty" feed:"optional"`
	Description string   `json:"description,omitempty" feed:"optional"`
	UserComment string   `json:"user_comment,omitempty" feed:"optional"`
	NextURL     string   `json:"next_url,omitempty" feed:"optional"`
	Icon        string   `json:"icon,omitempty" feed:"optional"`
	Favicon     string   `json:"favicon,omitempty" feed:"optional"`
	Author      Author   `json:"author,omitempty" feed:"optional"`
	Items       []*Item  `json:"items,omitempty" feed:"optional"`
	Expired     bool     `json:"expired,omitempty" feed:"optional"`
	Hubs        []string `json:"hubs,omitempty" feed:"optional"`
}

JSONFeed The structure of a JSON Feed

func CreateJSONFeed

func CreateJSONFeed(title string, description string) (feed *JSONFeed)

CreateJSONFeed creates a new json feed (v1)

func OpenFeed

func OpenFeed(url string) (feed *JSONFeed, err error)

OpenFeed read from url into a JSONFeed

func (JSONFeed) GetMissing

func (jf JSONFeed) GetMissing() (missing []string, err error)

GetMissing checks if the feed has all the required fields

func (*JSONFeed) PublishHTML

func (jf *JSONFeed) PublishHTML(id string, title string, textHTML string, attachments ...*Attachment) (i *Item)

PublishHTML publishes a new html text item to a JSON Feed, the publish date is time.Now()

func (*JSONFeed) PublishText

func (jf *JSONFeed) PublishText(id string, title string, text string, attachments ...*Attachment) (i *Item)

PublishText publishes a new plain text item to a JSON Feed, the publish date is time.Now()

func (*JSONFeed) Read

func (jf *JSONFeed) Read(r io.Reader) error

func (*JSONFeed) ServeHTTP

func (jf *JSONFeed) ServeHTTP(rw http.ResponseWriter, r *http.Request)

func (*JSONFeed) SetVersion

func (jf *JSONFeed) SetVersion(v int)

SetVersion set the version JSON Feed to use

func (*JSONFeed) Write

func (jf *JSONFeed) Write(w io.Writer) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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