Documentation
¶
Index ¶
- Constants
- Variables
- func EncryptNotification(message []byte, keys Keys, recordSize uint32) ([]byte, error)
- func SendNotification(ctx context.Context, message []byte, s *Subscription, options *Options) (*http.Response, error)
- type HTTPClient
- type Keys
- type Options
- type Subscription
- type Urgency
- type VAPIDKeys
Constants ¶
const MaxRecordSize uint32 = 4096
Variables ¶
var (
ErrRecordSizeTooSmall = errors.New("record size too small for message")
)
Functions ¶
func EncryptNotification ¶
EncryptNotification implements the encryption algorithm specified by RFC 8291 for web push (RFC 8188's aes128gcm content-encoding, with the key material derived from elliptic curve Diffie-Hellman over the P-256 curve).
Types ¶
type HTTPClient ¶
HTTPClient is an interface for sending the notification HTTP request / testing
type Keys ¶
Keys represents a subscription's keys (its ECDH public key on the P-256 curve and its 16-byte authentication secret).
func DecodeSubscriptionKeys ¶
DecodeSubscriptionKeys decodes and validates a base64-encoded pair of subscription keys (the authentication secret and ECDH public key).
func (*Keys) MarshalJSON ¶
MarshalJSON implements json.Marshaler, allowing serialization to JSON.
func (*Keys) UnmarshalJSON ¶
MarshalJSON implements json.Unmarshaler, allowing deserialization from JSON.
type Options ¶
type Options struct { HTTPClient HTTPClient // Will replace with *http.Client by default if not included RecordSize uint32 // Limit the record size Subscriber string // Sub in VAPID JWT token Topic string // Set the Topic header to collapse a pending messages (Optional) TTL int // Set the TTL on the endpoint POST request, in seconds Urgency Urgency // Set the Urgency header to change a message priority (Optional) VAPIDKeys *VAPIDKeys // VAPID public-private keypair to generate the VAPID Authorization header VapidExpiration time.Time // optional expiration for VAPID JWT token (defaults to now + 12 hours) }
Options are config and extra params needed to send a notification
type Subscription ¶
Subscription represents a PushSubscription object from the Push API
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 device state: on power and Wi-Fi UrgencyVeryLow Urgency = "very-low" // UrgencyLow requires device state: on either power or Wi-Fi UrgencyLow Urgency = "low" // UrgencyNormal excludes device state: low battery UrgencyNormal Urgency = "normal" // UrgencyHigh admits device state: low battery UrgencyHigh Urgency = "high" )
type VAPIDKeys ¶
type VAPIDKeys struct {
// contains filtered or unexported fields
}
VAPIDKeys is a public-private keypair for use in VAPID. It marshals to a JSON string containing the PEM of the PKCS8 of the private key.
func DecodeLegacyVAPIDPrivateKey ¶
DecodeLegacyVAPIDPrivateKey decodes the legacy string private key format returned by GenerateVAPIDKeys in v1.
func ECDSAToVAPIDKeys ¶
func ECDSAToVAPIDKeys(privKey *ecdsa.PrivateKey) (result *VAPIDKeys, err error)
ECDSAToVAPIDKeys wraps an existing ecdsa.PrivateKey in VAPIDKeys for use in VAPID header signing.
func GenerateVAPIDKeys ¶
GenerateVAPIDKeys generates a VAPID keypair (an ECDSA keypair on the P-256 curve).
func (*VAPIDKeys) MarshalJSON ¶
MarshalJSON implements json.Marshaler, allowing serialization to JSON.
func (*VAPIDKeys) PrivateKey ¶
func (v *VAPIDKeys) PrivateKey() *ecdsa.PrivateKey
PrivateKey returns the private key of the keypair.
func (*VAPIDKeys) PublicKeyString ¶
PublicKeyString returns the base64url-encoded uncompressed public key of the keypair, as defined in RFC8292.
func (*VAPIDKeys) UnmarshalJSON ¶
MarshalJSON implements json.Unmarshaler, allowing deserialization from JSON.