pubsub

package
v0.0.0-...-75625ea Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2017 License: BSD-3-Clause Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alter

func Alter(hub, topic, callbackURL, mode string) error

func MakeCallbackURL

func MakeCallbackURL(baseURL, id string) string

func Subscribe

func Subscribe(hub, topic, callbackURL string) error

func Unsubscribe

func Unsubscribe(hub, topic, callbackURL string) error

Types

type Client

type Client struct {
	CallbackURL string
	State       State
	OnMessage   MessageHandler
}

func NewClient

func NewClient(callbackURL string, state State, onMessage MessageHandler) *Client

func (*Client) Handler

func (c *Client) Handler() *Handler

func (*Client) Refresh

func (c *Client) Refresh(forceUpdate bool, interval time.Duration) error

func (*Client) Subscribe

func (c *Client) Subscribe(hub, topic string) error

func (*Client) Unsubscribe

func (c *Client) Unsubscribe(hub, topic string) error

type Handler

type Handler struct {
	OnChallenge func(id, topic, mode string, leaseTime time.Duration) error
	OnMessage   func(id, topic string, rd io.ReadCloser)
}

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request)

type MessageHandler

type MessageHandler func(id string, s *Subscription, rd io.ReadCloser)

type SQLiteState

type SQLiteState struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

func NewSQLiteState

func NewSQLiteState(db *sql.DB) *SQLiteState

func (*SQLiteState) Add

func (s *SQLiteState) Add(hub, topic, baseURL string) (*Subscription, string, error)

func (*SQLiteState) All

func (s *SQLiteState) All() ([]Subscription, error)

func (*SQLiteState) Del

func (s *SQLiteState) Del(hub, topic string) error

func (*SQLiteState) Get

func (s *SQLiteState) Get(hub, topic string) (*Subscription, error)

func (*SQLiteState) GetByID

func (s *SQLiteState) GetByID(id string) (*Subscription, error)

func (*SQLiteState) Set

func (s *SQLiteState) Set(hub, topic string, updatedAt, expiresAt time.Time) error

type State

type State interface {
	All() (subscriptions []Subscription, err error)
	Add(hub, topic, baseURL string) (subscription *Subscription, oldCallbackURL string, err error)
	Get(hub, topic string) (subscription *Subscription, err error)
	GetByID(id string) (subscription *Subscription, err error)
	Set(hub, topic string, updatedAt, expiresAt time.Time) (err error)
	Del(hub, topic string) (err error)
}

type Subscription

type Subscription struct {
	ID          string
	Hub         string
	Topic       string
	CallbackURL string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	ExpiresAt   *time.Time
}

Jump to

Keyboard shortcuts

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