mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-22 02:04:10 +01:00
.. | ||
.check-gofmt.sh | ||
.gitignore | ||
CHANGELOG.md | ||
legacy.go | ||
LICENSE | ||
Makefile | ||
README.md | ||
urgency.go | ||
vapid.go | ||
webpush.go |
webpush-go
Web Push API Encryption with VAPID support.
This library is a fork of SherClockHolmes/webpush-go.
go get -u github.com/ergochat/webpush-go/v2
Example
For a full example, refer to the code in the example directory.
package main
import (
"encoding/json"
"github.com/ergochat/webpush-go/v2"
webpush )
func main() {
// Decode subscription
:= &webpush.Subscription{}
s .Unmarshal([]byte("<YOUR_SUBSCRIPTION>"), s)
json:= new(webpush.VAPIDKeys)
vapidKeys .Unmarshal([]byte("<YOUR_VAPID_KEYS">), vapidKeys)
json
// Send Notification
, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
resp: "example@example.com",
Subscriber: vapidKeys,
VAPIDKeys: 3600, // seconds
TTL})
if err != nil {
// TODO: Handle error
}
defer resp.Body.Close()
}
Generating VAPID Keys
Use the helper method GenerateVAPIDKeys
to generate the
VAPID key pair.
vapidKeys, err := webpush.GenerateVAPIDKeys()
if err != nil {
// TODO: Handle error
}
Development
- Install Go 1.20+
go mod vendor
go test