Documentation
¶
Overview ¶
Package push implements the (frozen) Web Push notifications behind the webui panel (design P3-26): the VAPID identity (RFC 8292), message encryption (RFC 8291 over the aes128gcm content coding from RFC 8188), subscription storage, and delivery to the browser's push service. The browser side lives in webui/web/pwa (service worker + subscription).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Notification ¶
type Notification struct {
Title string `json:"title"`
Body string `json:"body"`
ID string `json:"id"`
Icon string `json:"icon,omitempty"`
Badge string `json:"badge,omitempty"`
}
Notification is the JSON payload delivered to the browser. The service worker reads title/body/id to render and group the notification (webui/web/pwa/sw.js). Icon and Badge carry the PWA icon URLs so a push shows the app mark even on a platform that does not render the manifest icon automatically (P2-17).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service owns the VAPID identity, the subscription store, and delivery.
func NewService ¶
NewService builds a push Service. logger may be nil.
func (*Service) Notify ¶
func (s *Service) Notify(ctx context.Context, n Notification) error
Notify broadcasts one notification to every subscription. Per-device failures are logged, not propagated: a single dead endpoint must not suppress pushes to healthy devices.
func (*Service) PublicKey ¶
PublicKey returns the base64url applicationServerKey the browser subscribes with.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists push subscriptions in SQLite, one row per device.
func (*Store) Add ¶
func (s *Store) Add(ctx context.Context, sub Subscription) error
Add upserts a subscription keyed by endpoint, so a browser that re-subscribes (e.g. after a permission change) replaces its old keys in place.
type Subscription ¶
type Subscription struct {
Endpoint string `json:"endpoint"`
Keys struct {
P256dh string `json:"p256dh"`
Auth string `json:"auth"`
} `json:"keys"`
}
Subscription is a browser PushSubscription as serialized by PushSubscription.toJSON(): the delivery endpoint plus the ECDH public key and auth secret needed to encrypt messages for that device.
type VAPIDKeys ¶
type VAPIDKeys struct {
// contains filtered or unexported fields
}
VAPIDKeys is the application-server identity used to sign push requests. The ECDSA P-256 keypair doubles as the browser's applicationServerKey: its public point is what the browser subscribes with, and the same key signs each request so the push service can verify the sender.
func GenerateVAPIDKeys ¶
GenerateVAPIDKeys creates a fresh P-256 identity for subject.
func LoadOrCreateVAPIDKeys ¶
LoadOrCreateVAPIDKeys reads the PEM-encoded key at path (the subject is not persisted), or generates and writes a new one. Keys must be stable across restarts: rotating the applicationServerKey invalidates every browser subscription, so a fresh key per boot would silently break delivery.