Categorygithub.com/dapperlabs/webpush-go
modulepackage
1.1.1
Repository: https://github.com/dapperlabs/webpush-go.git
Documentation: pkg.go.dev

# README

webpush-go

Web Push API Encryption with VAPID support.

go get -u https://github.com/dapperlabs/webpush-go

Example

For a full example, refer to the code in the example directory.

package main

import (
	"encoding/json"

	webpush "https://github.com/dapperlabs/webpush-go"
)

func main() {
	// Decode subscription
	s := &webpush.Subscription{}
	json.Unmarshal([]byte("<YOUR_SUBSCRIPTION>"), s)

	// Send Notification
	_, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
		Subscriber:      "[email protected]",
		VAPIDPublicKey:  "<YOUR_VAPID_PUBLIC_KEY>",
		VAPIDPrivateKey: "<YOUR_VAPID_PRIVATE_KEY>",
		TTL:             30,
	})
	if err != nil {
		// TODO: Handle error
	}
}

Generating VAPID Keys

Use the helper method GenerateVAPIDKeys to generate the VAPID key pair.

privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
if err != nil {
	// TODO: Handle error
}

Development

  1. Install Go 1.11+
  2. go mod vendor
  3. go test

For other language implementations visit:

WebPush Libs

# Packages

No description provided by the author

# Functions

GenerateVAPIDKeys will create a private and public VAPID key pair.
SendNotification sends a push notification to a subscription's endpoint Message Encryption for Web Push, and VAPID protocols.

# Constants

No description provided by the author
UrgencyHigh admits device state: low battery.
UrgencyLow requires device state: on either power or Wi-Fi.
UrgencyNormal excludes device state: low battery.
UrgencyVeryLow requires device state: on power and Wi-Fi.

# Structs

Keys are the base64 encoded values from PushSubscription.getKey().
Options are config and extra params needed to send a notification.
Subscription represents a PushSubscription object from the Push API.

# Interfaces

HTTPClient is an interface for sending the notification HTTP request / testing.

# Type aliases

Urgency indicates to the push service how important a message is to the user.