gotosocial/vendor/github.com/SherClockHolmes/webpush-go
dependabot[bot] a773768718
[chore]: Bump github.com/SherClockHolmes/webpush-go from 1.3.0 to 1.4.0 (#3694)
Bumps [github.com/SherClockHolmes/webpush-go](https://github.com/SherClockHolmes/webpush-go) from 1.3.0 to 1.4.0.
- [Release notes](https://github.com/SherClockHolmes/webpush-go/releases)
- [Commits](https://github.com/SherClockHolmes/webpush-go/compare/v1.3.0...v1.4.0)

---
updated-dependencies:
- dependency-name: github.com/SherClockHolmes/webpush-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-01-27 11:08:13 +00:00
..
.gitignore [feature] Push notifications (#3587) 2025-01-23 16:47:30 -08:00
LICENSE [feature] Push notifications (#3587) 2025-01-23 16:47:30 -08:00
README.md [feature] Push notifications (#3587) 2025-01-23 16:47:30 -08:00
urgency.go [feature] Push notifications (#3587) 2025-01-23 16:47:30 -08:00
vapid.go [chore]: Bump github.com/SherClockHolmes/webpush-go from 1.3.0 to 1.4.0 (#3694) 2025-01-27 11:08:13 +00:00
webpush.go [chore]: Bump github.com/SherClockHolmes/webpush-go from 1.3.0 to 1.4.0 (#3694) 2025-01-27 11:08:13 +00:00

webpush-go

Go Report Card GoDoc

Web Push API Encryption with VAPID support.

go get -u github.com/SherClockHolmes/webpush-go

Example

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

package main

import (
	"encoding/json"

	webpush "github.com/SherClockHolmes/webpush-go"
)

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

	// Send Notification
	resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
		Subscriber:      "example@example.com",
		VAPIDPublicKey:  "<YOUR_VAPID_PUBLIC_KEY>",
		VAPIDPrivateKey: "<YOUR_VAPID_PRIVATE_KEY>",
		TTL:             30,
	})
	if err != nil {
		// TODO: Handle error
	}
	defer resp.Body.Close()
}

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