push

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: AGPL-3.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func NewService(keys *VAPIDKeys, store *Store, logger *slog.Logger) *Service

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

func (s *Service) PublicKey() string

PublicKey returns the base64url applicationServerKey the browser subscribes with.

func (*Service) Subscribe

func (s *Service) Subscribe(ctx context.Context, sub Subscription) error

Subscribe validates and stores a browser subscription.

func (*Service) Unsubscribe

func (s *Service) Unsubscribe(ctx context.Context, endpoint string) error

Unsubscribe removes the subscription for endpoint.

type Store

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

Store persists push subscriptions in SQLite, one row per device.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore wraps db for subscription CRUD. The table is created by storage.Migrate.

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.

func (*Store) All

func (s *Store) All(ctx context.Context) ([]Subscription, error)

All lists every stored subscription, oldest first.

func (*Store) Remove

func (s *Store) Remove(ctx context.Context, endpoint string) error

Remove deletes the subscription for endpoint.

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

func GenerateVAPIDKeys(subject string) (*VAPIDKeys, error)

GenerateVAPIDKeys creates a fresh P-256 identity for subject.

func LoadOrCreateVAPIDKeys

func LoadOrCreateVAPIDKeys(path, subject string) (*VAPIDKeys, error)

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.

func (*VAPIDKeys) PublicKey

func (k *VAPIDKeys) PublicKey() string

PublicKey returns the uncompressed P-256 point, base64url-encoded, for use as the browser's applicationServerKey.

Jump to

Keyboard shortcuts

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