Documentation ¶
Overview ¶
Package webpush implements Web Push helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeKey ¶
DecodeKey returns the bytes represented by the base64 string s. This can be used to decode new subscription p256dh and auth keys.
func GenerateKey ¶
GenerateKey returns a new ECDSA private key from a secure random source.
Types ¶
type Option ¶
type Option func(*WebPush)
Option represents a functional option for configuration.
func WithExpiry ¶
WithExpiry sets the duration with which to expire the push.
func WithPusher ¶
WithPusher sets the pusher. Defaults to a sane HTTP client for most use cases.
type PushOption ¶
PushOption represents a functional option for push configuration.
func WithTTL ¶
func WithTTL(ttl int) PushOption
WithTTL sets the TTL header. Defaults to 60 seconds.
func WithUrgency ¶
func WithUrgency(urgency Urgency) PushOption
WithUrgency sets the Urgency header.
type Subscription ¶
Subscription represents a subscription to a Web Push service.
type Urgency ¶
type Urgency string
Urgency indicates to the push service how important a message is to the user. This can be used by the push service to help conserve the battery life of a user’s device by only waking up for important messages when battery is low.
const ( // UrgencyVeryLow requires the device to be on power and wifi. // Useful for advertisements. UrgencyVeryLow Urgency = "very-low" // UrgencyLow requires the device to be on either power or wifi. // Useful for topic updates. UrgencyLow Urgency = "low" // UrgencyNormal requires the device to be on neither power nor wifi. // Useful for chats or calendar reminders. UrgencyNormal Urgency = "normal" // UrgencyHigh will operate on low battery. // Useful for time-sensitive alerts. UrgencyHigh Urgency = "high" )
type WebPush ¶
type WebPush struct {
// contains filtered or unexported fields
}
WebPush represents the Web Push application server.
func New ¶
New returns a new Web Push application server. privateKey must be a PEM-encoded ECDSA private key. Generate a valid key with GenerateKey.
func (*WebPush) PublicKey ¶
PublicKey returns the public application server key for use in JavaScript client web push subscription.
func (*WebPush) Push ¶
func (c *WebPush) Push(s *Subscription, b []byte, opts ...PushOption) (*http.Response, error)
Push sends a push notification.