pubsubhubbub

package
v0.0.0-...-30adf6a Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 17 Imported by: 3

Documentation

Overview

Package pubsubhubbub implements PubSubHubbub, as defined in http://pubsubhubbub.github.io/PubSubHubbub/pubsubhubbub-core-0.4.html.

Index

Constants

View Source
const (
	// RelHub is the hub relation.
	RelHub = "hub"
	// RelUpdatesFrom is the updates-from relation.
	RelUpdatesFrom = "http://schemas.google.com/g/2010#updates-from"
)

Variables

View Source
var DefaultLease = 24 * time.Hour

DefaultLease is the default duration of a lease, if none is provided by the subscriber.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Subscribe sends content notifications about a topic to notifies in a new
	// goroutine. The notifies channel should only be closed after a call to
	// Unsubscribe. If the subscription is not possible, it should return a
	// DeniedError.
	Subscribe(topic string, notifies chan<- Event) error
	// Unsubscribe closes notifies. The notifies channel must have been provided
	// to Subscribe.
	Unsubscribe(notifies chan<- Event) error
}

A Backend is used to build a publisher.

type DeniedError

type DeniedError string

A DeniedError is returned when a publisher forbids subscription to a feed. Its value is the reason.

func (DeniedError) Error

func (err DeniedError) Error() string

Error implements error.

type Event

type Event interface {
	// MediaType returns the event's media type.
	MediaType() string
	// Topic returns the event's topic URL.
	Topic() string
	// WriteTo writes the event's body to w.
	WriteTo(w io.Writer) error
}

An Event is a notification sent by a publisher and received by a subscriber.

type HTTPError

type HTTPError int

An HTTPError is an HTTP error. Its value is the HTTP status code.

func (HTTPError) Error

func (err HTTPError) Error() string

Error implements error.

type Publisher

type Publisher struct {
	// SubscriptionState specifies an optional callback function that is called
	// when a subscription changes state. leaseEnd is zero if the subscription
	// ends.
	SubscriptionState func(topicURL, callbackURL, secret string, leaseEnd time.Time)
	// contains filtered or unexported fields
}

A Publisher distributes content notifications.

func NewPublisher

func NewPublisher(be Backend) *Publisher

NewPublisher creates a new publisher.

func (*Publisher) Register

func (p *Publisher) Register(topicURL, callbackURL, secret string, leaseEnd time.Time) error

Register registers an existing subscription. It can be used to restore subscriptions when restarting the server.

func (*Publisher) ServeHTTP

func (p *Publisher) ServeHTTP(resp http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.

func (*Publisher) Subscribe

func (p *Publisher) Subscribe(topicURL, callbackURL, secret string, lease time.Duration) error

Subscribe processes a subscribe request.

func (*Publisher) Unsubscribe

func (p *Publisher) Unsubscribe(topicURL, callbackURL string) error

Unsubscribe processes an unsubscribe request.

type ReadEventFunc

type ReadEventFunc func(mediaType string, body io.Reader) (Event, error)

ReadEventFunc reads an event.

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields
}

A Subscriber subscribes to publishers.

func NewSubscriber

func NewSubscriber(callbackURL string, readEvent ReadEventFunc) *Subscriber

NewSubscriber creates a new subscriber.

func (*Subscriber) ServeHTTP

func (s *Subscriber) ServeHTTP(resp http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(hub, topic string, notifies chan<- Event) error

Subscribe subscribes to a topic on a hub. Notifications are sent to notifies.

func (*Subscriber) Unsubscribe

func (s *Subscriber) Unsubscribe(hub, topic string) error

Unsubscribe unsubscribes from a topic on a hub.

Jump to

Keyboard shortcuts

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