webpush

package
v0.0.0-...-8acab51 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package webpush provides Web Push notification support using VAPID authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOrCreateVAPIDKeys

func GetOrCreateVAPIDKeys(kv kvstore.Store) (privateKey, publicKey string, err error)

GetOrCreateVAPIDKeys returns VAPID keys, generating and persisting them on first call. Keys are stored in the kvstore under "config:webpush_vapid".

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler provides HTTP endpoints for Web Push subscription management.

func NewHandler

func NewHandler(store *Store, publicKey string) *Handler

NewHandler creates a new Web Push handler.

func (*Handler) GetVAPIDKey

func (h *Handler) GetVAPIDKey(c echo.Context) error

GetVAPIDKey returns the VAPID public key for browser subscription.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(g *echo.Group)

RegisterRoutes registers Web Push routes on the given echo group.

func (*Handler) Subscribe

func (h *Handler) Subscribe(c echo.Context) error

Subscribe saves a push subscription for the authenticated user.

func (*Handler) Unsubscribe

func (h *Handler) Unsubscribe(c echo.Context) error

Unsubscribe removes a push subscription.

type Sender

type Sender struct {
	// contains filtered or unexported fields
}

Sender delivers Web Push notifications to subscribed browsers.

func NewSender

func NewSender(privateKey, publicKey string, store *Store, logger *zap.Logger) *Sender

NewSender creates a new Web Push sender.

func (*Sender) SendToAll

func (s *Sender) SendToAll(ctx context.Context, title, body, imageURL string) error

SendToAll sends a push notification to all subscribed browsers (broadcast). Useful for single-user systems like ZimaOS. imageURL is optional.

func (*Sender) SendToUser

func (s *Sender) SendToUser(ctx context.Context, userID, title, body string) error

SendToUser sends a push notification to all of a user's subscribed browsers.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store provides SQLite-backed persistence for push subscriptions.

func NewStore

func NewStore(db *sql.DB) (*Store, error)

NewStore creates a new push subscription store.

func NewStoreWithReadDB

func NewStoreWithReadDB(writeDB, readDB *sql.DB) (*Store, error)

NewStoreWithReadDB creates a new push subscription store with separate write and read database handles.

func (*Store) DeleteByEndpoint

func (s *Store) DeleteByEndpoint(ctx context.Context, endpoint string) error

DeleteByEndpoint removes a subscription by endpoint (for stale cleanup).

func (*Store) ListAll

func (s *Store) ListAll(ctx context.Context) ([]*Subscription, error)

ListAll returns all subscriptions (for broadcast).

func (*Store) ListByUser

func (s *Store) ListByUser(ctx context.Context, userID string) ([]*Subscription, error)

ListByUser returns all subscriptions for a user.

func (*Store) Subscribe

func (s *Store) Subscribe(ctx context.Context, userID string, sub *Subscription) error

Subscribe upserts a push subscription for a user.

func (*Store) Unsubscribe

func (s *Store) Unsubscribe(ctx context.Context, endpoint string) error

Unsubscribe removes a subscription by endpoint.

type Subscription

type Subscription struct {
	ID        int64     `json:"id"`
	UserID    string    `json:"user_id"`
	Endpoint  string    `json:"endpoint"`
	KeyP256dh string    `json:"key_p256dh"`
	KeyAuth   string    `json:"key_auth"`
	CreatedAt time.Time `json:"created_at"`
}

Subscription represents a Web Push subscription from a browser.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL