Documentation
¶
Overview ¶
Package webpush sends RFC 8030 Web Push messages to the browser push services: RFC 8291 payload encryption, RFC 8292 application server identification, and nothing else. It knows about a VAPID key pair, a subscription, and an HTTP client, so it can be lifted out of the server unchanged.
Index ¶
- Constants
- Variables
- func DecodeKey(value string) ([]byte, error)
- func GenerateKeys() (publicKey, privateKey string, err error)
- func KeyFingerprint(publicKey string) string
- func NormalizeSubject(subject string) (string, error)
- func RelayHost(endpoint string) string
- func ValidateKeys(publicKey, privateKey string) error
- func ValidateSubscriptionKeys(p256dh, auth string) error
- type Message
- type RelayError
- type Sender
- type Subscription
Constants ¶
const ( // MaxBodyRunes bounds the message text a notification carries. Lock // screens truncate long bodies anyway, and the payload has to stay inside // one encrypted record. MaxBodyRunes = 240 )
Variables ¶
var ErrSubscriptionGone = errors.New("push subscription is gone")
ErrSubscriptionGone reports that the push service has permanently rejected the subscription. The caller deletes the stored row; no other failure means the device is gone.
Functions ¶
func DecodeKey ¶
DecodeKey accepts the base64url a browser, an operator, or a config file is likely to carry: with or without padding, and with the standard alphabet.
func GenerateKeys ¶
GenerateKeys returns a fresh base64url VAPID key pair, public key first. The public key is the uncompressed P-256 point the browser passes to pushManager.subscribe; the private key is the raw scalar.
func KeyFingerprint ¶
KeyFingerprint names a VAPID public key in a log line: the first twelve hex digits of the SHA-256 of its bytes, so every spelling of one key agrees. The key is public; the fingerprint keeps the line short and changes when the operator rotates the pair.
func NormalizeSubject ¶
NormalizeSubject returns the RFC 8292 contact for the application server. A value that already carries its scheme is kept byte for byte: push services reject a doubled "mailto:" prefix, and Apple rejects every push that carries one.
func RelayHost ¶
RelayHost reports the push service host for a subscription endpoint. It is the only part of an endpoint that is safe to log: the path carries the device's delivery secret.
func ValidateKeys ¶
ValidateKeys rejects malformed or mismatched VAPID identities before devices register.
func ValidateSubscriptionKeys ¶
ValidateSubscriptionKeys rejects client keys that cannot produce a payload: a p256dh that is not a point on P-256, or an auth secret of the wrong length. Registration calls it so a device can never be stored in a state the delivery worker would choke on.
Types ¶
type Message ¶
type Message struct {
UserID string `json:"user_id"`
Title string `json:"title"`
Body string `json:"body"`
Tag string `json:"tag"`
URL string `json:"url"`
}
Message is the payload a service worker receives.
type RelayError ¶
RelayError is a push service refusal that says nothing about whether the subscription is still good: rate limits, outages, and anything else the service reports with a status code. The caller backs off.
func (*RelayError) Error ¶
func (e *RelayError) Error() string
type Subscription ¶
Subscription is the durable half of a browser PushSubscription.