🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

meow.tf/websub

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

meow.tf/websub

Go Modules
Version
v1.4.1
Version published
Created
Source

Go WebSub Server

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

See examples/main.go for a basic example which uses boltdb and a simple publisher.

Importing:

go get meow.tf/websub

Features

  • Acts as a package to allow implementation using your favorite HTTP router (See Hub.ServeHTTP, as well as each Handle method for implementation in other routers that aren't stdlib compliant)
  • Allows publishing of events directly from the hub, for use with custom implementations (such as a bridge for services that don't support hubs)
  • Supports secrets and sha1, sha256, sha384, sha512 validation
  • Supports Content-Type forwarding.
  • Supports external workers to scale past what a single server can do (See Workers)

Stores

Specific stores can be implemented/used to store subscriptions and call them.

If you'd like to implement your own store, the following interface can be implemented:

// Store defines an interface for stores to implement for data storage.
type Store interface {
	// All returns all subscriptions for the specified topic.
	All(topic string) ([]model.Subscription, error)

	// For returns the subscriptions for the specified callback
	For(callback string) ([]model.Subscription, error)

	// Add saves/adds a subscription to the store.
	Add(sub model.Subscription) error

	// Get retrieves a subscription given a topic and callback.
	Get(topic, callback string) (*model.Subscription, error)

	// Remove removes a subscription from the store.
	Remove(sub model.Subscription) error
}

Memory

A memory-backed store. This store is cleared when the application is restarted.

Bolt

A boltdb/bbolt backed store which persists to disk.

Workers

This hub system uses Workers to implement a system that can be infinitely scaled by adding other nodes/servers and workers which can pull off a queue.

By default, the worker pool is a basic channel + goroutine handler that goes through each request.

type Worker interface {
    Add(f PublishJob)
    Start()
    Stop()
}

When implementing workers, pay attention to the fields. ContentType is used to say what the body content type is (required by the specification), and if subscription.secret is set it MUST be used to generate an X-Hub-Signature header.

Using it with your own Publisher

If you wish to bypass the included hub.mode=publish handler, you can use the Publish function to publish your own data.

For example, if you're taking an event off some kind of queue/event subscriber:

hub.Publish("https://example.com", "application/json", []byte("{}"))

FAQs

Package last updated on 08 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts