forked from SherClockHolmes/webpush-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ergochat/ecdh_update.6
update to v2 API
- Loading branch information
Showing
17 changed files
with
1,150 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
SOURCES="." | ||
|
||
if [ "$1" = "--fix" ]; then | ||
exec gofmt -s -w $SOURCES | ||
fi | ||
|
||
if [ -n "$(gofmt -s -l $SOURCES)" ]; then | ||
echo "Go code is not formatted correctly with \`gofmt -s\`:" | ||
gofmt -s -d $SOURCES | ||
exit 1 | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: "build" | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "master" | ||
- "stable" | ||
push: | ||
branches: | ||
- "master" | ||
- "stable" | ||
|
||
jobs: | ||
build: | ||
runs-on: "ubuntu-22.04" | ||
steps: | ||
- name: "checkout repository" | ||
uses: "actions/checkout@v3" | ||
- name: "setup go" | ||
uses: "actions/setup-go@v3" | ||
with: | ||
go-version: "1.23" | ||
- name: "make test" | ||
run: "make test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ vendor/** | |
|
||
.DS_Store | ||
*.out | ||
|
||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Changelog | ||
All notable changes to webpush-go will be documented in this file. | ||
|
||
## [2.0.0] - 2025-01-01 | ||
|
||
* Update the `Keys` struct definition to store `Auth` as `[16]byte` and `P256dh` as `*ecdh.PublicKey` | ||
* `Keys` can no longer be compared with `==`; use `(*Keys.Equal)` instead | ||
* The JSON representation has not changed and is backwards and forwards compatible with v1 | ||
* `DecodeSubscriptionKeys` is a helper to decode base64-encoded auth and p256dh parameters into a `Keys`, with validation | ||
* Update the `VAPIDKeys` struct to contain a `(*ecdsa.PrivateKey)` | ||
* `VAPIDKeys` can no longer be compared with `==`; use `(*VAPIDKeys).Equal` instead | ||
* The JSON representation is now a JSON string containing the PEM of the PKCS8-encoded private key | ||
* To parse the legacy representation (raw bytes of the private key encoded in base64), use `DecodeLegacyVAPIDPrivateKey` | ||
* Renamed `SendNotificationWithContext` to `SendNotification`, removing the earlier `SendNotification` API. (Pass `context.Background()` as the context to restore the former behavior.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.PHONY: test | ||
|
||
test: | ||
go test . | ||
go vet . | ||
./.check-gofmt.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
# webpush-go | ||
|
||
[![Go Report Card](https://goreportcard.com/badge/github.com/SherClockHolmes/webpush-go)](https://goreportcard.com/report/github.com/SherClockHolmes/webpush-go) | ||
[![GoDoc](https://godoc.org/github.com/SherClockHolmes/webpush-go?status.svg)](https://godoc.org/github.com/SherClockHolmes/webpush-go) | ||
[![GoDoc](https://godoc.org/github.com/ergochat/webpush-go?status.svg)](https://godoc.org/github.com/ergochat/webpush-go) | ||
|
||
Web Push API Encryption with VAPID support. | ||
|
||
This library is a fork of [SherClockHolmes/webpush-go](https://github.com/SherClockHolmes/webpush-go). | ||
|
||
```bash | ||
go get -u github.com/SherClockHolmes/webpush-go | ||
go get -u github.com/ergochat/webpush-go/v2 | ||
``` | ||
|
||
## Example | ||
|
@@ -19,20 +20,21 @@ package main | |
import ( | ||
"encoding/json" | ||
|
||
webpush "github.com/SherClockHolmes/webpush-go" | ||
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: "[email protected]", | ||
VAPIDPublicKey: "<YOUR_VAPID_PUBLIC_KEY>", | ||
VAPIDPrivateKey: "<YOUR_VAPID_PRIVATE_KEY>", | ||
TTL: 30, | ||
VAPIDKeys: vapidKeys, | ||
TTL: 3600, // seconds | ||
}) | ||
if err != nil { | ||
// TODO: Handle error | ||
|
@@ -46,15 +48,15 @@ func main() { | |
Use the helper method `GenerateVAPIDKeys` to generate the VAPID key pair. | ||
|
||
```golang | ||
privateKey, publicKey, err := webpush.GenerateVAPIDKeys() | ||
vapidKeys, err := webpush.GenerateVAPIDKeys() | ||
if err != nil { | ||
// TODO: Handle error | ||
} | ||
``` | ||
|
||
## Development | ||
|
||
1. Install [Go 1.11+](https://golang.org/) | ||
1. Install [Go 1.20+](https://golang.org/) | ||
2. `go mod vendor` | ||
3. `go test` | ||
|
||
|
Oops, something went wrong.