# README
webpush-go
Web Push API Encryption with VAPID support.
go get -u github.com/SherClockHolmes/webpush-go
Example
package main
import (
"bytes"
"encoding/json"
"log"
webpush "github.com/sherclockholmes/webpush-go"
)
const (
vapidPrivateKey = "<YOUR VAPID PRIVATE KEY>"
)
func main() `
// Decode subscription
s := webpush.Subscription
if err := json.NewDecoder(bytes.NewBufferString(subJSON)).Decode(&s); err != nil
// Send Notification
_, err := webpush.SendNotification([]byte("Test"), &s, &webpush.Options)
if err != nil
Generating VAPID Keys
Use the helper method GenerateVAPIDKeys
to generate the VAPID key pair.
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
if err != nil
Development
References
For more information visit these Google Developers links:
https://developers.google.com/web/updates/2016/03/web-push-encryption
https://developers.google.com/web/updates/2016/07/web-push-interop-wins
Similar Projects / Inspired By
# Functions
GenerateVAPIDKeys will create a private and public VAPID key pair.
SendNotification sends a push notification to a subscriptions endpoint Follows the Message Encryption for Web Push, and VAPID protocols.
# Constants
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 exposed interface to pass in custom http.Client.
# Type aliases
Urgency indicates to the push service how important a message is to the user.