Versions in this module Expand all Collapse all v1 v1.0.2 Jul 26, 2026 v1.0.1 Jul 26, 2026 Changes in this version + const DefaultDeliveryAttempts + const DefaultDeliveryBackoff + const DefaultDeliveryConcurrent + const DefaultLease + const DefaultMaxBodySize + const DefaultMaxLease + const DefaultMinLease + const DefaultRenewAt + const DefaultSignatureAlgorithm + const MaxDiscoveryBody + const MaxSecretLength + const SignatureHeader + var ErrDiscoveryFailed = errors.New("websub: could not discover hub/topic") + var ErrInvalidSignature = errors.New("websub: signature verification failed") + var ErrLeaseOutOfRange = errors.New("websub: requested lease outside allowed range") + var ErrSubscriptionDenied = errors.New("websub: hub denied subscription") + var ErrUnknownSubscription = errors.New("websub: no such subscription") + func Sign(alg SignatureAlgorithm, secret string, body []byte) (string, error) + func Verify(header, secret string, body []byte) error + func WithMaxBodySize(n int64) interface + type DenialError struct + Reason string + Topic string + func (e *DenialError) Error() string + func (e *DenialError) Is(target error) bool + type Discovery struct + ContentType string + Hubs []string + Topic string + func Discover(ctx context.Context, topicURL string) (*Discovery, error) + func (d *Discovery) Hub() string + type Hooks struct + OnDeliveryFailure func(sub HubSubscription, err error) + OnPublish func(topic string) + OnSubscribe func(sub HubSubscription) + OnUnsubscribe func(sub HubSubscription) + type Hub struct + func NewHub(hubURL string, opts ...HubOption) (*Hub, error) + func (h *Hub) AddSniffer(topic string, fn func(topic, contentType string, body []byte)) + func (h *Hub) AddValidator(fn func(*HubSubscription) (ok bool, reason string)) + func (h *Hub) Publish(ctx context.Context, topic, contentType string, body []byte) error + func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request) + func (h *Hub) Shutdown(ctx context.Context) error + func (h *Hub) Subscriptions(ctx context.Context, topic string) ([]Subscription, error) + func (h *Hub) Topics(ctx context.Context) ([]string, error) + func (h *Hub) URL() string + type HubOption interface + func WithDeliveryConcurrency(n int) HubOption + func WithDeliveryRetry(attempts int, backoff time.Duration) HubOption + func WithHooks(h Hooks) HubOption + func WithLeaseBounds(minLease, maxLease time.Duration) HubOption + func WithSignatureAlgorithm(alg SignatureAlgorithm) HubOption + func WithStore(s SubscriptionStore) HubOption + type HubSubscription struct + CreatedAt time.Time + Failures int + LastDelivery time.Time + LastStatus int + type Link struct + Rels []string + URL string + func ParseLinkHeader(values []string, base *url.URL) []Link + func (l Link) HasRel(rel string) bool + type Mode int + const ModePuSH04 + const ModeWebSub + func (m Mode) String() string + type Option interface + func WithHTTPClient(c *http.Client) Option + func WithLogger(l *slog.Logger) Option + func WithMode(m Mode) Option + func WithUserAgent(ua string) Option + type Publisher struct + func NewPublisher(baseURL string, opts ...PublisherOption) (*Publisher, error) + func (p *Publisher) Advertise(topic string) http.Header + func (p *Publisher) Hubs() []string + func (p *Publisher) Middleware(topic string, next http.Handler) http.Handler + func (p *Publisher) Publish(ctx context.Context, topic, contentType string, body []byte) error + func (p *Publisher) TopicURL(topic string) string + type PublisherOption interface + func WithHubs(hubURLs ...string) PublisherOption + type SignatureAlgorithm string + const SHA1 + const SHA256 + const SHA384 + const SHA512 + func (a SignatureAlgorithm) Valid() bool + type SubscribeOption interface + func WithHub(hubURL string) SubscribeOption + func WithLease(d time.Duration) SubscribeOption + func WithSecret(secret string) SubscribeOption + func WithTopic(topicURL string) SubscribeOption + type Subscriber struct + func NewSubscriber(callbackURL string, opts ...SubscriberOption) (*Subscriber, error) + func (s *Subscriber) Await(ctx context.Context, sub *Subscription) (*Subscription, error) + func (s *Subscriber) Close() error + func (s *Subscriber) Discover(ctx context.Context, topicURL string) (*Discovery, error) + func (s *Subscriber) Forget(sub *Subscription) + func (s *Subscriber) OnNotify(fn func(sub *Subscription, contentType string, body []byte)) + func (s *Subscriber) ServeHTTP(w http.ResponseWriter, r *http.Request) + func (s *Subscriber) Subscribe(ctx context.Context, topic string, opts ...SubscribeOption) (*Subscription, error) + func (s *Subscriber) Subscriptions() []Subscription + func (s *Subscriber) Unsubscribe(ctx context.Context, sub *Subscription) error + type SubscriberOption interface + func WithRenewAt(fraction float64) SubscriberOption + func WithoutAutoRenew() SubscriberOption + type Subscription struct + Callback string + ExpiresAt time.Time + Hub string + Lease time.Duration + Secret string + State SubscriptionState + Topic string + func (s Subscription) Expired(now time.Time) bool + type SubscriptionState int + const StateActive + const StateDenied + const StateExpired + const StatePending + const StateUnsubscribed + func (s SubscriptionState) String() string + type SubscriptionStore interface + Delete func(ctx context.Context, topic, callback string) error + Get func(ctx context.Context, topic, callback string) (Subscription, error) + ListByTopic func(ctx context.Context, topic string) ([]Subscription, error) + ListExpiring func(ctx context.Context, before time.Time) ([]Subscription, error) + Save func(ctx context.Context, sub Subscription) error + Topics func(ctx context.Context) ([]string, error) + func NewMemoryStore() SubscriptionStore