webpush

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 21 Imported by: 0

README

webpush

Package webpush supports Generic Event Delivery Using HTTP Push.

Compatibility

This package has been tested with:

  • Linux/Firefox
  • Linux/Google Chrome
  • iOS/Safari
  • macOS/Safari
  • Android/Firefox

References

Documentation

Overview

Package webpush supports Generic Event Delivery Using HTTP Push.

Generic Event Delivery Using HTTP Push https://www.rfc-editor.org/rfc/rfc8030.html

Message Encryption for Web Push https://www.rfc-editor.org/rfc/rfc8291.html

Voluntary Application Server Identification (VAPID) for Web Push https://www.rfc-editor.org/rfc/rfc8292

Encrypted Content-Encoding for HTTP: https://www.rfc-editor.org/rfc/rfc8188

MDN Push API: https://developer.mozilla.org/en-US/docs/Web/API/Push_API

Apple Push Notification Documentation: https://developer.apple.com/documentation/usernotifications/sending-web-push-notifications-in-web-apps-and-browsers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateVAPIDKey

func GenerateVAPIDKey() (string, error)

GenerateVAPIDKey will create a private VAPID key in Base64 Raw URL Encoding. Generate a key and store it in your configuration. Use ParseVAPIDKey on application startup to parse it for use in the Config.

func ParseVAPIDKey

func ParseVAPIDKey(privateKey string) (*ecdsa.PrivateKey, error)

ParseVAPIDKey parses a private key encoded in Base64 Raw URL Encoding. Use GenerateVAPIDKey to generate a key for use in your application.

func Send

func Send(ctx context.Context, message []byte, s *Subscription, conf *Config) (*http.Response, error)

Send a Push Notification to a Subscription.

Types

type Config

type Config struct {
	Client          *http.Client      // Required http.Client.
	VAPIDKey        *ecdsa.PrivateKey // Required VAPID Private Key.
	Subscriber      string            // Required Subscriber, https URL or mailto: email address.
	TTL             time.Duration     // Required TTL on the endpoint POST request (rounded to seconds).
	Topic           string            // Optional Topic to collapse pending messages.
	Urgency         Urgency           // Optional Urgency for message priority.
	RecordSize      int               // Optional custom RecordSize, defaults to 4096 per spec.
	VAPIDExpiration time.Time         // Optional custom expiration for VAPID JWT token (defaults to now + 12 hours).
}

Config specifies required and optional aspects for sending a Push Notification.

type Keys

type Keys struct {
	Auth   string `json:"auth"`
	P256dh string `json:"p256dh"`
}

Keys are the Base64 encoded values from the User Agent.

type Subscription

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

Subscription represents a PushSubscription from the User Agent.

type Urgency

type Urgency string

Urgency directly impacts battery life.

https://www.rfc-editor.org/rfc/rfc8030.html#section-5.3

const (
	// UrgencyVeryLow targets "On power and Wi-Fi".
	UrgencyVeryLow Urgency = "very-low"
	// UrgencyLow targets "On either power or Wi-Fi".
	UrgencyLow Urgency = "low"
	// UrgencyNormal targets "On neither power nor Wi-Fi".
	UrgencyNormal Urgency = "normal"
	// UrgencyHigh targets any state including "Low battery".
	UrgencyHigh Urgency = "high"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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