1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
package main
import (
"encoding/json"
webpush "github.com/SherClockHolmes/webpush-go"
)
const (
subscription = ``
vapidPublicKey = ""
vapidPrivateKey = ""
)
func main() {
// Decode subscription
s := &webpush.Subscription{}
json.Unmarshal([]byte(subscription), s)
// Send Notification
resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
Subscriber: "example@example.com", // Do not include "mailto:"
VAPIDPublicKey: vapidPublicKey,
VAPIDPrivateKey: vapidPrivateKey,
TTL: 30,
})
if err != nil {
// TODO: Handle error
}
defer resp.Body.Close()
}
|