1
0
Fork 0
mirror of https://github.com/imjasonh/webpush synced 2026-07-11 09:40:00 +00:00

Implement Web Push API Go library with VAPID support and pluggable storage

Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-24 21:19:16 +00:00
parent 7d0082c045
commit 78bd40dc88
15 changed files with 2708 additions and 1 deletions

46
storage/storage.go Normal file
View file

@ -0,0 +1,46 @@
// Package storage provides interfaces and implementations for storing
// web push subscriptions.
package storage
import (
"context"
"time"
"github.com/imjasonh/webpush"
)
// Record represents a stored subscription with metadata.
type Record struct {
ID string `json:"id"`
UserID string `json:"user_id,omitempty"`
Subscription *webpush.Subscription `json:"subscription"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Storage defines the interface for storing web push subscriptions.
type Storage interface {
// Save stores or updates a subscription.
Save(ctx context.Context, record *Record) error
// Get retrieves a subscription by ID.
Get(ctx context.Context, id string) (*Record, error)
// GetByEndpoint retrieves a subscription by its endpoint URL.
GetByEndpoint(ctx context.Context, endpoint string) (*Record, error)
// GetByUserID retrieves all subscriptions for a user.
GetByUserID(ctx context.Context, userID string) ([]*Record, error)
// Delete removes a subscription by ID.
Delete(ctx context.Context, id string) error
// DeleteByEndpoint removes a subscription by its endpoint URL.
DeleteByEndpoint(ctx context.Context, endpoint string) error
// List returns all subscriptions with pagination.
List(ctx context.Context, limit, offset int) ([]*Record, error)
// Close closes the storage connection.
Close() error
}