https://github.com/catho/webpush-go
Web Push API Encryption with VAPID support.
https://github.com/catho/webpush-go
Last synced: 6 months ago
JSON representation
Web Push API Encryption with VAPID support.
- Host: GitHub
- URL: https://github.com/catho/webpush-go
- Owner: catho
- License: mit
- Fork: true (SherClockHolmes/webpush-go)
- Created: 2022-09-28T12:34:27.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-28T19:38:16.000Z (almost 4 years ago)
- Last Synced: 2024-06-20T16:44:57.843Z (about 2 years ago)
- Homepage:
- Size: 37.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# webpush-go
[](https://goreportcard.com/report/github.com/catho/webpush-go)
[](https://godoc.org/github.com/catho/webpush-go)
Web Push API Encryption with VAPID support.
```bash
go get -u github.com/catho/webpush-go
```
## Example
For a full example, refer to the code in the [example](example/) directory.
```go
package main
import (
"encoding/json"
webpush "github.com/catho/webpush-go"
)
func main() {
// Decode subscription
s := &webpush.Subscription{}
json.Unmarshal([]byte(""), s)
// Send Notification
resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
Subscriber: "example@example.com",
VAPIDPublicKey: "",
VAPIDPrivateKey: "",
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.
```golang
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
if err != nil {
// TODO: Handle error
}
```
## Development
1. Install [Go 1.11+](https://golang.org/)
2. `go mod vendor`
3. `go test`
#### For other language implementations visit:
[WebPush Libs](https://github.com/web-push-libs)