push

package
v2.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 22 Imported by: 0 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 is the web-push (VAPID) notification sink. It degrades to a no-op until keys are configured, so a fresh install never fails on it.

The payload is encrypted with RFC 8291 aes128gcm and authorised with an RFC 8292 VAPID JWT. Implemented directly on crypto/* rather than pulling a dependency: it is ~120 lines and the alternative is another module to audit.

Index

Constants

View Source
const (
	SettingPrivateKey = "vapid_private"
	SettingPublicKey  = "vapid_public"
)

Settings keys the resolved VAPID key pair is persisted under. Deliberately NOT in sinks.Keys: GET/PUT /api/settings never touches them, so there is no API path — not even an admin one — that can read the private key back out, and PUT /api/settings rejects them the same way it rejects any unknown key.

Variables

This section is empty.

Functions

func GenerateKeyPair added in v2.4.0

func GenerateKeyPair() (privateKey, publicKey string, err error)

GenerateKeyPair mints a fresh P-256 VAPID key pair, in the same base64url raw-scalar (private) / uncompressed-point (public) encoding every other key in this package uses. Used to auto-provision a Sender when no LECTERN_VAPID_PRIVATE/PUBLIC are set — see ResolveKeys.

Types

type Sender

type Sender struct {
	PrivateKey string // base64url raw P-256 scalar
	PublicKey  string // base64url uncompressed P-256 point
	Email      string
	Client     *http.Client
	Log        *slog.Logger
}

Sender holds the VAPID identity.

func ResolveKeys added in v2.4.0

func ResolveKeys(db *store.DB, envPrivate, envPublic, envEmail string, log *slog.Logger) (*Sender, error)

ResolveKeys builds the Sender lectern runs with, so a phone alert works without the owner ever configuring keys by hand.

LECTERN_VAPID_PRIVATE/PUBLIC win when both are set — an operator's explicit choice, e.g. to share one identity across installs. Otherwise a pair is loaded from the settings table; the very first start generates one and persists it, so every start after that reuses the same identity (a browser subscription is bound to the public key it subscribed with — rotating it silently would orphan every existing subscription).

func (*Sender) Enabled

func (s *Sender) Enabled() bool

Enabled reports whether VAPID keys are configured.

func (*Sender) Send

func (s *Sender) Send(sub Subscription, payload []byte) (gone bool, err error)

Send delivers one notification. It returns whether the subscription is gone (404/410), so the caller can prune it.

type Subscription

type Subscription struct {
	Endpoint string            `json:"endpoint"`
	Keys     map[string]string `json:"keys"`
}

Subscription is a browser's push endpoint plus its encryption keys.

Jump to

Keyboard shortcuts

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