client

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: ISC Imports: 25 Imported by: 0

README

Go WebSub Client

A Go implementation of a WebSub client. It has been tested to pass every WebSub Rocks! Subscriber test.

See examples/basic.go for a basic example which uses a built-in webserver to subscribe.

Looking for a server? Check out WebSub Server!

Importing:

go get meow.tf/websub/client

Features

  • Acts as it's own http server, or can be used externally by using VerifySubscription and handing requests yourself.
  • Supports secrets and sha1, sha256, sha384, sha512 validation
  • Integrates into the matching WebSub Server stores to use the same across both.
  • Supports discovery of HTTP Headers, RSS, Atom, and HTML for hubs.
  • Correctly follows topic and hub redirects, as well as uses the discovered "self" url instead of the passed topic.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoHub        = errors.New("hub not found")
	ErrNoSelf       = errors.New("self link not found")
	ErrNoChallenge  = errors.New("no challenge specified")
	ErrInvalidLease = errors.New("invalid lease duration")

	DefaultLease = 24 * time.Hour
)

Functions

func ValidateSignature

func ValidateSignature(body []byte, secret, signature string) bool

ValidateSignature is a helper method to validate a signature a hub sends.

Types

type Client

type Client struct {
	*handler.Handler
	// contains filtered or unexported fields
}

Client represents a websub client

func New

func New(callbackBase string, options ...Option) *Client

New creates a new client with the specified callback base url and options

func (*Client) Discover

func (c *Client) Discover(topicURL string) (string, string, error)

Discover pulls

func (*Client) ServeHTTP

func (c *Client) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP lets this client be used as a handler for HTTP servers.

func (*Client) Subscribe

func (c *Client) Subscribe(opts SubscribeOptions) (*model.Subscription, error)

Subscribe creates a new websub request

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(opts UnsubscribeOptions) error

Unsubscribe sends an unsubscription request to the hub

func (*Client) VerifySubscription

func (c *Client) VerifySubscription(mode, topic, requestUrl string, v url.Values) ([]byte, error)

VerifySubscription lets other handlers pass subscriptions, unsubscribes, and denied errors themselves.

type Option

type Option func(c *Client)

Option is an option type for definition client options

func WithCallbackBase

func WithCallbackBase(base string) Option

WithCallbackBase sets the base callback url

func WithHttpClient

func WithHttpClient(client *http.Client) Option

WithHttpClient lets you override the client's http client

func WithLeaseDuration

func WithLeaseDuration(duration time.Duration) Option

WithLeaseDuration lets you override the default lease duration request

func WithStore

func WithStore(s store.Store) Option

WithStore sets the Client's subscription store

type Publish

type Publish struct {
	Subscription model.Subscription
	ContentType  string
	Data         []byte
}

Publish is called when items are published

type SubscribeOptions

type SubscribeOptions struct {
	Hub      string
	Topic    string
	Callback string
	Secret   string
	Lease    time.Duration
}

SubscribeOptions are options sent to the hub for subscriptions

type SubscriptionDenied

type SubscriptionDenied struct {
	Subscription *model.Subscription
	Reason       string
}

type UnsubscribeOptions added in v0.2.0

type UnsubscribeOptions struct {
	Hub      string
	Topic    string
	Callback string
}

UnsubscribeOptions allows the use of a custom Hub for unsubscribes. This used to be UnsubscribeRequest from the base model, but was changed for simplicity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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