Files
zeekayandHanzo Dev 849f862587 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-16 19:21:21 -07:00
..

Webpush Notifications

go.dev reference

Prerequisites

Generate VAPID Public and Private Keys for the notification service. This can be done using many tools, one of which is GenerateVAPIDKeys from webpush-go.

Compatibility

This service is compatible with the Web Push Protocol and VAPID.

For a list of compatible browsers, see this for the Push API and this for the Web Notifications.

Usage

package main

import (
	"context"
	"log"

	"github.com/hanzo-iam/notify2"
	"github.com/hanzo-iam/notify2/service/webpush"
)

const vapidPublicKey = "..."  // Add a vapidPublicKey
const vapidPrivateKey = "..." // Add a vapidPrivateKey

func main() {
	subscription := webpush.Subscription{
		Endpoint: "https://your-endpoint",
		Keys: {
			Auth:   "...",
			P256dh: "...",
		},
	}

	webpushSvc := webpush.New(vapidPublicKey, vapidPrivateKey)
	webpushSvc.AddReceivers(subscription)

	notifier := notify.NewWithServices(webpushSvc)

	if err := notifier.Send(context.Background(), "TEST", "Message using golang notifier library"); err != nil {
		log.Fatalf("notifier.Send() failed: %s", err.Error())
	}

	log.Println("Notification sent successfully")
}