Documentation
¶
Overview ¶
Package push owns Web Push plumbing: per-install VAPID keys, browser subscription store, and the encrypted POST that wakes a service worker when the notifier dispatches a new event.
Index ¶
Constants ¶
const VAPIDSubject = "https://github.com/geodro/lerd"
VAPIDSubject identifies this app in the JWT "sub" claim. HTTPS URLs are accepted by every push service; mailto: with non-routable hosts isn't.
Variables ¶
var HTTPClient = &http.Client{Timeout: 10 * time.Second}
HTTPClient is the http.Client webpush-go uses; tests swap in a recorder.
Functions ¶
func Add ¶
func Add(s Subscription) error
func Send ¶
func Send(n Notification) error
Send fans the notification out to every stored subscription and prunes any subscription the push service has retired (404 / 410). Single entry point: no parallel SendBytes/SendAll exists.
func VAPIDKeys ¶
VAPIDKeys returns the per-install VAPID key pair, generating it on first call and persisting both halves under the data dir.
func VAPIDPublicKey ¶
Types ¶
type Notification ¶
type Notification struct {
Kind string `json:"kind"`
Title string `json:"title,omitempty"`
TitleKey string `json:"title_key,omitempty"`
Body string `json:"body,omitempty"`
BodyKey string `json:"body_key,omitempty"`
Params map[string]string `json:"params,omitempty"`
Tag string `json:"tag,omitempty"`
URL string `json:"url,omitempty"`
Icon string `json:"icon,omitempty"`
Data map[string]string `json:"data,omitempty"`
TTL int `json:"-"`
Urgency string `json:"-"`
}
Notification is the kind-agnostic shape every push or WS broadcast carries. Title/Body are pre-resolved English fallbacks; TitleKey/BodyKey + Params drive Paraglide localisation on the page side. TTL/Urgency are HTTP-only.
func (Notification) Payload ¶
func (n Notification) Payload() ([]byte, error)
type Subscription ¶
type Subscription struct {
Endpoint string `json:"endpoint"`
P256dh string `json:"p256dh"`
Auth string `json:"auth"`
UA string `json:"ua,omitempty"`
AddedAt int64 `json:"added_at"`
Enabled bool `json:"enabled"`
EnabledKinds []string `json:"enabled_kinds,omitempty"`
}
Subscription is the persisted per-browser push subscription. EnabledKinds gates push fan-out so a user can mute categories per device; an empty slice with Enabled=true means "all kinds" (default for new subs).
func List ¶
func List() ([]Subscription, error)
func (Subscription) Allows ¶
func (s Subscription) Allows(kind string) bool
Allows reports whether this subscription should receive a push for the given notification kind. "test" is always allowed so users can verify the pipeline even when no categories are toggled on.