webpush

package
v0.0.0-...-acbe8ed Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package webpush provides Web Push notification sending support (VAPID + Push API).

Index

Constants

This section is empty.

Variables

View Source
var ErrPushServiceError = errors.New("webpush: push service error")

ErrPushServiceError is returned when the push service responds with an unexpected non-2xx, non-404/410 status code.

View Source
var ErrSubscriptionGone = errors.New("webpush: subscription gone")

ErrSubscriptionGone is returned when the push service reports the subscription is no longer valid (HTTP 404 or 410). The caller must soft-delete the corresponding UserContact or prune it from channel Settings.

Functions

func GetOrCreateVAPIDKeys

func GetOrCreateVAPIDKeys(ctx context.Context, cfg Config, dbSvc db.Service) (string, string, error)

GetOrCreateVAPIDKeys returns the server's VAPID keypair. It reads VAPIDPublicKey / VAPIDPrivateKey from cfg first; if absent, reads from the app_settings table; if still absent, generates a new pair, persists both to app_settings, and returns them. Must be called once during app startup and the result stored in config.

func Send

func Send(ctx context.Context, opts Options, subscriptionJSON string, msg Message) error

Send encrypts msg and POSTs it to the push service endpoint encoded in subscriptionJSON (a JSON-serialized PushSubscription from the browser). Returns ErrSubscriptionGone for 404/410 responses.

Types

type Config

type Config struct {
	VAPIDPublicKey  string
	VAPIDPrivateKey string
	Subject         string
	Enabled         bool
}

Config holds the web-push configuration used for VAPID key management. It mirrors the relevant fields from config.WebPushConfig.

type Message

type Message struct {
	Title string `json:"title"`
	Body  string `json:"body"`
	URL   string `json:"url"` // incident or check URL to open on click
}

Message is the payload sent via Web Push.

type Options

type Options struct {
	VAPIDPublicKey  string
	VAPIDPrivateKey string
	// Subject is the VAPID subject — a mailto: or URL string as required by the spec.
	Subject string
}

Options holds the VAPID credentials and subject required for signing pushes.

Jump to

Keyboard shortcuts

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