push

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher sends Web Push notifications to every stored subscription.

func NewDispatcher

func NewDispatcher(store *Store, vapid VAPID, subscriber string) *Dispatcher

NewDispatcher builds a dispatcher over the given store and VAPID keys.

func (*Dispatcher) Notify

func (d *Dispatcher) Notify(n Notification)

Notify fans n out to all subscriptions, pruning any the push service reports as gone (404/410). Best-effort: per-subscription failures are logged, not returned.

func (*Dispatcher) VAPIDPublicKey

func (d *Dispatcher) VAPIDPublicKey() string

VAPIDPublicKey returns the public key browsers need to subscribe.

type Notification

type Notification struct {
	Title     string `json:"title"`
	Body      string `json:"body,omitempty"`
	SessionID string `json:"session_id,omitempty"`
	Tag       string `json:"tag,omitempty"` // coalesces same-session notifications on the device
}

Notification is the payload delivered (encrypted) to the service worker, which turns it into a system notification. Keep it minimal: it ends up on the lock screen, so no prompts, tool args, paths, diffs or final text — just a type and the session title.

type Store

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

Store is a thread-safe, disk-backed set of Web Push subscriptions keyed by endpoint. Single-user personal use over the tailnet — no per-user identity; a subscription is one browser/device that opted in.

func NewStore

func NewStore(path string) (*Store, error)

NewStore loads subscriptions from path (empty if the file does not exist yet).

func (*Store) Add

func (s *Store) Add(sub webpush.Subscription) error

Add stores (or replaces) a subscription by endpoint and persists. Idempotent.

func (*Store) All

func (s *Store) All() []webpush.Subscription

All returns a snapshot slice of the current subscriptions.

func (*Store) Len

func (s *Store) Len() int

Len reports how many subscriptions are stored.

func (*Store) Remove

func (s *Store) Remove(endpoint string) error

Remove deletes a subscription by endpoint and persists. No-op if absent.

type VAPID

type VAPID struct {
	Public  string `json:"public"`
	Private string `json:"private"`
}

VAPID is the server's VAPID key pair (RFC 8292). The public key is shared with browsers (application server key); the private key signs the VAPID JWT and must stay secret (persisted 0600).

func LoadOrGenerateVAPID

func LoadOrGenerateVAPID(path string) (VAPID, error)

LoadOrGenerateVAPID reads the VAPID key pair from path, generating and persisting a new pair (0600) on first use. The pair is stable across restarts so existing browser subscriptions keep working.

Jump to

Keyboard shortcuts

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