Documentation
¶
Overview ¶
Package push sends Web Push notifications (RFC 8030, 8291 and 8292) to the phones and browsers that turned them on; it owns push_subscriptions (schema.sql) and calls the app's backoffice for the session. A notification is a nudge, never the only place something is said: the app shows the same thing.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Hosts = []string{".push.apple.com", "fcm.googleapis.com", ".push.services.mozilla.com", ".notify.windows.com"}
Hosts are the push services a subscription may point at, by host or host suffix: the server posts to whatever endpoint a phone sends, so no other host is reached.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DB *sql.DB
Backoffice *backoffice.Backoffice
// Keys is the zero value when notifications are off.
Keys Keys
// Subject is the contact the push services may reach the sender at: a mailto: or https: URL.
Subject string
// Welcome is sent to a phone as it subscribes; the subscription is kept only once it went through.
Welcome Message
}
Config is what New needs; the app copies schema.sql into its migrations.
type Keys ¶
type Keys struct {
// Public is the uncompressed P-256 point, base64url: the applicationServerKey the phones subscribe with.
Public string
// contains filtered or unexported fields
}
Keys is the VAPID key pair (RFC 8292) the push services know this server by.
type Message ¶
type Message struct {
Title string `json:"title"`
Body string `json:"body"`
URL string `json:"url"`
Tag string `json:"tag,omitempty"`
}
Message is what the kit's service worker shows; Tag replaces an earlier notification with the same tag instead of stacking.
type Service ¶
type Service struct {
Client *http.Client
Hosts []string
// contains filtered or unexported fields
}
Service sends the notifications and serves the subscription routes.
func New ¶
New makes the service; Client and Hosts may be replaced before use (tests point them at a local push service).
func (*Service) Mount ¶
Mount adds GET /api/v1/push (the key) and PUT and DELETE /api/v1/push/subscription, behind the session check.
func (*Service) On ¶
On reports whether a VAPID key is set: without one, nothing is sent and subscriptions are refused.