gohubbub

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

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

README

GoHubbub

A PubSubHubbub subscriber client library for Go (golang).

For API documentation see https://godoc.org/github.com/mycode-inst/gohubbub

Example

gohubbub can start its own HTTP server:

import "github.com/mycode-inst/gohubbub"

// ...

client := gohubbub.NewClient("mysite.com", "Testing")
client.DiscoverAndSubscribe(topicURL, func(contentType string, body []byte) {
  // Handle update notification.
})
client.StartAndServe("", 80)

Or if you have your own server, you can register the gohubbub request handler on your own mux and then call client.Run() when your server is running:

import "github.com/mycode-inst/gohubbub"

// ...

client := gohubbub.NewClient("mysite.com", "Testing")
client.DiscoverAndSubscribe(topicURL, func(contentType string, body []byte) {
  // Handle update notification.
})
client.RegisterHandler(myMux)

// ...

client.Start()

See this simple program for a fully functioning example. You will need to run it from a machine that is publicly accessible or use reverse port forwarding from one that is.

Contributing

Questions, comments, bug reports, and pull requests are all welcome. Submit them on the project issue tracker.

License

Copyright 2022 mycode-inst. Licensed under the Apache License, Version 2.0.

Documentation

Overview

Package gohubbub provides a PubSubHubbub subscriber client. It will request subscriptions from a hub and handle responses as required by the prootcol. Update notifications will be forwarded to the handler function that was registered on subscription.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client allows you to register a callback for PubSubHubbub subscriptions, handlers will be executed when an update is received.

func NewClient

func NewClient(self string, from string) *Client

func (*Client) Discover

func (client *Client) Discover(topic string) (string, error)

Discover queries an RSS or Atom feed for the hub which it is publishing to.

func (*Client) DiscoverAndSubscribe

func (client *Client) DiscoverAndSubscribe(topic string, handler func(string, []byte)) error

DiscoverAndSubscribe queries an RSS or Atom feed for the hub which it is publishing to, then subscribes for updates.

func (*Client) HasSubscription

func (client *Client) HasSubscription(topic string) bool

HasSubscription returns true if a subscription exists for the topic.

func (*Client) RegisterHandler

func (client *Client) RegisterHandler(mux *http.ServeMux)

RegisterHandler binds the client's HandlerFunc to the provided MUX on the path /push-callback/

func (*Client) Start

func (client *Client) Start()

Start makes the initial subscription requests and marks the client as running. Before calling, RegisterHandler should be called with a running server.

func (*Client) StartAndServe

func (client *Client) StartAndServe(addr string, port int)

StartAndServe starts a server using DefaultServeMux, and makes initial subscription requests.

func (Client) String

func (client Client) String() string

String provides a textual representation of the client's current state.

func (*Client) Subscribe

func (client *Client) Subscribe(hub, topic string, handler func(string, []byte))

Subscribe adds a handler will be called when an update notification is received. If a handler already exists for the given topic it will be overridden.

func (*Client) Unsubscribe

func (client *Client) Unsubscribe(topic string)

Unsubscribe sends an unsubscribe notification and removes the subscription.

type HttpRequester

type HttpRequester interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

A HttpRequester is used to make HTTP requests. http.Client{} satisfies this interface.

Directories

Path Synopsis
cmd
example
A very simple PubSubHubbub subscriber client that watches a feed that can be easily updated by visiting http://push-pub.appspot.com/.
A very simple PubSubHubbub subscriber client that watches a feed that can be easily updated by visiting http://push-pub.appspot.com/.
medium
A PubSubHubbub subscriber client that watches Medium's latest feed.
A PubSubHubbub subscriber client that watches Medium's latest feed.

Jump to

Keyboard shortcuts

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