webpush

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package webpush is the Web Push wire adapter: VAPID key generation, RFC 8291 payload encryption with RFC 8292 VAPID authorization, and classification of push service responses. It holds no storage or diffx policy.

Index

Constants

View Source
const (
	UrgencyVeryLow = "very-low"
	UrgencyLow     = "low"
	UrgencyNormal  = "normal"
	UrgencyHigh    = "high"
)

Urgency values defined by RFC 8030.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(keys Keys, subject string, options ...Option) *Client

New signs requests with keys. Subject identifies the application server to push services: an https URL or a mailto: address.

func (*Client) Send

func (c *Client) Send(ctx context.Context, subscription Subscription, payload []byte, options Options) Result

Send encrypts payload for the subscription and posts it to its endpoint.

type Keys

type Keys struct {
	Public  string
	Private string
}

Keys is a VAPID key pair: the base64url uncompressed P-256 public point browsers use as applicationServerKey, and the base64url private scalar.

func GenerateKeys

func GenerateKeys() (Keys, error)

GenerateKeys creates a VAPID key pair.

type Option

type Option func(*Client)

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient replaces the default client, which times out after 30 seconds.

type Options

type Options struct {
	TTL     time.Duration
	Topic   string
	Urgency string
}

Options are the RFC 8030 message headers. Topic replaces an undelivered message with the same topic; it must be at most 32 base64url characters.

type Outcome

type Outcome int

Outcome classifies a push service response.

const (
	// Accepted: the push service took the message (2xx).
	Accepted Outcome = iota
	// Gone: the subscription expired or was unsubscribed (404, 410).
	Gone
	// Retry: rate limited, a server failure or a network error (429, 5xx).
	Retry
	// Permanent: the push service refused this message (other 4xx, including 413).
	Permanent
)

func (Outcome) String

func (outcome Outcome) String() string

type Result

type Result struct {
	Outcome    Outcome
	Status     int
	RetryAfter time.Duration
	Err        error
}

Result is a classified send. RetryAfter carries the push service's Retry-After when it gave one; Status is zero without a response.

type Subscription

type Subscription struct {
	Endpoint string
	P256dh   string
	Auth     string
}

Subscription is a browser PushSubscription: its endpoint and base64url keys.

Jump to

Keyboard shortcuts

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