Skip to content

Commit 73cb41c

Browse files
committed
documentation updates
1 parent 2decbc9 commit 73cb41c

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ vendor/**
22

33
.DS_Store
44
*.out
5+
6+
*.swp

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
All notable changes to webpush-go will be documented in this file.
3+
4+
## [2.0.0] - 2025-01-01
5+
6+
* Update the `Keys` struct definition to store `Auth` as `[16]byte` and `P256dh` as `*ecdh.PublicKey`
7+
* `Keys` can no longer be compared with `==`; use `(*Keys.Equal)` instead
8+
* The JSON representation has not changed and is backwards and forwards compatible with v1
9+
* `DecodeSubscriptionKeys` is a helper to decode base64-encoded auth and p256dh parameters into a `Keys`, with validation
10+
* Update the `VAPIDKeys` struct to contain a `(*ecdsa.PrivateKey)`
11+
* `VAPIDKeys` can no longer be compared with `==`; use `(*VAPIDKeys).Equal` instead
12+
* The JSON representation is now a JSON string containing the PEM of the PKCS8-encoded private key
13+
* To parse the legacy representation (raw bytes of the private key encoded in base64), use `DecodeLegacyVAPIDPrivateKey`
14+
* Renamed `SendNotificationWithContext` to `SendNotification`, removing the earlier `SendNotification` API. (Pass `context.Background()` as the context to restore the former behavior.)

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# webpush-go
22

3-
[![Go Report Card](https://goreportcard.com/badge/github.com/SherClockHolmes/webpush-go)](https://goreportcard.com/report/github.com/SherClockHolmes/webpush-go)
4-
[![GoDoc](https://godoc.org/github.com/SherClockHolmes/webpush-go?status.svg)](https://godoc.org/github.com/SherClockHolmes/webpush-go)
3+
[![GoDoc](https://godoc.org/github.com/ergochat/webpush-go?status.svg)](https://godoc.org/github.com/ergochat/webpush-go)
54

65
Web Push API Encryption with VAPID support.
76

7+
This library is a fork of [SherClockHolmes/webpush-go](https://github.com/SherClockHolmes/webpush-go).
8+
89
```bash
9-
go get -u github.com/SherClockHolmes/webpush-go
10+
go get -u github.com/ergochat/webpush-go/v2
1011
```
1112

1213
## Example
@@ -19,20 +20,21 @@ package main
1920
import (
2021
"encoding/json"
2122

22-
webpush "github.com/SherClockHolmes/webpush-go"
23+
webpush "github.com/ergochat/webpush-go/v2"
2324
)
2425

2526
func main() {
2627
// Decode subscription
2728
s := &webpush.Subscription{}
2829
json.Unmarshal([]byte("<YOUR_SUBSCRIPTION>"), s)
30+
vapidKeys := new(webpush.VAPIDKeys)
31+
json.Unmarshal([]byte("<YOUR_VAPID_KEYS">), vapidKeys)
2932

3033
// Send Notification
3134
resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
3235
Subscriber: "example@example.com",
33-
VAPIDPublicKey: "<YOUR_VAPID_PUBLIC_KEY>",
34-
VAPIDPrivateKey: "<YOUR_VAPID_PRIVATE_KEY>",
35-
TTL: 30,
36+
VAPIDKeys: vapidKeys,
37+
TTL: 3600, // seconds
3638
})
3739
if err != nil {
3840
// TODO: Handle error
@@ -46,7 +48,7 @@ func main() {
4648
Use the helper method `GenerateVAPIDKeys` to generate the VAPID key pair.
4749

4850
```golang
49-
privateKey, publicKey, err := webpush.GenerateVAPIDKeys()
51+
vapidKeys, err := webpush.GenerateVAPIDKeys()
5052
if err != nil {
5153
// TODO: Handle error
5254
}

example/main.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
6+
"time"
57

6-
webpush "github.com/SherClockHolmes/webpush-go"
8+
webpush "github.com/ergochat/webpush-go/v2"
79
)
810

911
const (
1012
subscription = ``
11-
vapidPublicKey = ""
1213
vapidPrivateKey = ""
1314
)
1415

1516
func main() {
1617
// Decode subscription
17-
s := &webpush.Subscription{}
18-
json.Unmarshal([]byte(subscription), s)
18+
sub := &webpush.Subscription{}
19+
json.Unmarshal([]byte(subscription), sub)
20+
// Decode VAPID keys
21+
v := &webpush.VAPIDKeys{}
22+
json.Unmarshal([]byte(vapidPrivateKey), v)
1923

2024
// Send Notification
21-
resp, err := webpush.SendNotification([]byte("Test"), s, &webpush.Options{
22-
Subscriber: "example@example.com", // Do not include "mailto:"
23-
VAPIDPublicKey: vapidPublicKey,
24-
VAPIDPrivateKey: vapidPrivateKey,
25-
TTL: 30,
26-
})
25+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
26+
defer cancel()
27+
resp, err := webpush.SendNotification(
28+
ctx,
29+
[]byte("Test"),
30+
sub,
31+
&webpush.Options{
32+
Subscriber: "example@example.com", // Do not include "mailto:"
33+
VAPIDKeys: v,
34+
TTL: 30,
35+
},
36+
)
2737
if err != nil {
2838
// TODO: Handle error
2939
}

0 commit comments

Comments
 (0)