Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateVAPIDKeys() (privateKey, publicKey string, err error)
- func ValidUrgency(urgency Urgency) bool
- type Client
- func (o *Client) Send(subscription Subscription, message []byte) (*http.Response, error)
- func (o *Client) SendWithContext(ctx context.Context, s Subscription, message []byte, overrides ...Option) (*http.Response, error)
- func (o *Client) Set(opts ...Option) error
- func (c Client) SkipForEndpoint(endpoint string) bool
- type HTTPClient
- type Keys
- type MissingParameter
- type Option
- func SetClient(client HTTPClient) Option
- func SetExpirationDuration(d time.Duration) Option
- func SetPrivateKey(key string) Option
- func SetPublicKey(key string) Option
- func SetRecordSize(size uint32) Option
- func SetSubscriber(sub string) Option
- func SetTTL(ttl int, exclude ...string) Option
- func SetTTLDuration(ttl time.Duration) Option
- func SetTopic(topic string) Option
- func SetUrgency(urgency Urgency) Option
- type Subscription
- type Urgency
Constants ¶
Variables ¶
var ( ErrMaxPadExceeded = errors.New("payload has exceeded the maximum length") ErrNilClient = errors.New("client is nil") ErrEmptyParameter = errors.New("parameter is empty") ErrInvalidUrgency = errors.New("urgency is invalid") ErrNilSubscriptionEndpoint = errors.New("subscription endpoint is nil") ErrMissingSubscriptionAuth = errors.New("subscription is missing auth key") ErrMissingSubscriptionP256DH = errors.New("subscription is missing p256dh key") ErrInvalidSubscriber = errors.New("subscriber is neither a valid email or a https link") )
Functions ¶
func GenerateVAPIDKeys ¶
GenerateVAPIDKeys will create a private and public VAPID key pair
func ValidUrgency ¶
Checking allowable values for the urgency header
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client configuration that's needed to send a notification.
func (*Client) SendWithContext ¶
func (o *Client) SendWithContext(ctx context.Context, s Subscription, message []byte, overrides ...Option) (*http.Response, error)
SendWithContext sends a push notification to a subscription's endpoint Message Encryption for Web Push, and VAPID protocols. FOR MORE INFORMATION SEE RFC8291: https://datatracker.ietf.org/doc/rfc8291
func (Client) SkipForEndpoint ¶ added in v2.0.1
Check if the client will skip the endpoint.
Example: if you use SetTTL(0, "windows.com"), it will return true for "https://wns2-by3p.notify.windows.com/....".
type HTTPClient ¶
HTTPClient is an interface for sending the notification HTTP request / testing
type MissingParameter ¶
type MissingParameter string
func (MissingParameter) Error ¶
func (mp MissingParameter) Error() string
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option configures the client.
func SetClient ¶
func SetClient(client HTTPClient) Option
Clients sets the client to be used for the request.
client can not be nil
func SetExpirationDuration ¶
Set the expiration for VAPID JWT token
Duration is capped to 24 hours. See https://www.rfc-editor.org/rfc/rfc8292#section-2
func SetRecordSize ¶
SetRecordSize is used to limit the record size.
func SetTTL ¶
Set the TTL in seconds on the endpoint POST request.
Certain browsers may have issues when TTL is set to 0. TTL must be >= 0 to be set.
You can set the domains to exclude the zero ttl header with the exclude variable. This is not recommended.
func SetTTLDuration ¶ added in v2.1.0
Set the TTL Duration on the endpoint POST request.
Certain browsers may have issues when the TTL is set to 0.
func SetUrgency ¶
Set the Urgency header to change a message priority
type Subscription ¶
Subscription represents a PushSubscription object from the Push API
func (Subscription) Validate ¶ added in v2.0.1
func (s Subscription) Validate() error
Validate will check that everything is correct.
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" )