An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# webpush-go

[![Go Report Card](https://goreportcard.com/badge/github.com/catho/webpush-go)](https://goreportcard.com/report/github.com/catho/webpush-go)
[![GoDoc](https://godoc.org/github.com/catho/webpush-go?status.svg)](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)