3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-01-22 02:04:10 +01:00
ergo/vendor/github.com/ergochat/webpush-go/v2
2025-01-13 21:47:21 -05:00
..
.check-gofmt.sh implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
.gitignore implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
CHANGELOG.md implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
legacy.go implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
LICENSE implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
Makefile implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
README.md implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
urgency.go implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
vapid.go implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00
webpush.go implement draft/webpush (#2205) 2025-01-13 21:47:21 -05:00

webpush-go

GoDoc

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"

    webpush "github.com/ergochat/webpush-go/v2"
)

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

    // Send Notification
    resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
        Subscriber:      "example@example.com",
        VAPIDKeys:       vapidKeys,
        TTL:             3600, // seconds
    })
    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

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

For other language implementations visit:

WebPush Libs