Documentation ¶
Index ¶
- Variables
- type Message
- type RawMessage
- type Service
- type Subscription
- func (sub *Subscription) Authenticate(authorization string) error
- func (sub *Subscription) Expire()
- func (sub *Subscription) GetAuth() string
- func (sub *Subscription) GetChannel() <-chan *Message
- func (sub *Subscription) GetP256DH() string
- func (sub *Subscription) GetPath() string
- func (sub *Subscription) GetURL() string
- func (sub *Subscription) IsActive() bool
- func (sub *Subscription) IsRestricted() bool
- type SubscriptionOption
Constants ¶
This section is empty.
Variables ¶
var ErrForbidden = errors.New("Message was not authenticated while it is required (RFC8292 4.2., Forbidden)")
ErrForbidden represents a Forbidden error defined in RFC8292 4.2 https://tools.ietf.org/html/rfc8292#section-4-2
var ErrInvalidData = errors.New("Invalid data")
ErrInvalidData is an error returned when encountered an invalid data.
var ErrSubscriptionInactive = errors.New("Push attempt to expired subscription")
ErrSubscriptionInactive is an error only used for OnInvalidPush callback argument. Passed when received a push to inactive push subscription.
var ErrSubscriptionNotFound = errors.New("No subscription found")
ErrSubscriptionNotFound is an error only used for OnInvalidPush callback argument. Passed when received a push to nonexistent push subscription.
ErrUnauthorized represents an Unauthorized error defined in RFC8292 4.2 https://tools.ietf.org/html/rfc8292#section-4-2
var ErrUnencrypted = errors.New("Message should be encrypted but was not")
ErrUnencrypted is an error returned when a message wasn't encrypted while required to do so.
var ErrUnexpectedAuthorizationHeader = errors.New(`invalid or unexpected Authorization header`)
ErrUnexpectedAuthorizationHeader is an error when encountered unexpected, invalid Authorization header.
var ErrUnexpectedToken = errors.New(`VAPID key validation failure`)
ErrUnexpectedToken is an error returned when given pubilc key doesn't comply RFC8292 or doesn't match to the known expected public key.
var ErrUnrestricted = errors.New("unrestricted subscription is not permitted (RFC8292 Section 4.)")
ErrUnrestricted is an error returned when a subscription is required to be restricted, but isn't restricted.
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct { ID string Body []byte TTL int64 Topic string // contains filtered or unexported fields }
Message is a message
func (*Message) WasUnencrypted ¶
WasUnencrypted returns true when a message was not pushed with a encryption (RFC8291) and has a content.
type RawMessage ¶
RawMessage is a raw push message (might be encrypted) given at HTTP Push Request.
type Service ¶
type Service struct { Origin string OnInvalidPush func(id string, err error) // contains filtered or unexported fields }
Service is a web app of RFC8030, RFC8292 mock implementation
func (*Service) GetSubscriptionByID ¶
func (s *Service) GetSubscriptionByID(id string) *Subscription
GetSubscriptionByID finds a Subscription by its ID. nil when not exists.
func (*Service) Subscribe ¶
func (s *Service) Subscribe(option *SubscriptionOption, rejectUnencryptedMessage bool, rejectUnrestrictedSubscription bool) (*Subscription, error)
Subscribe returns a new push subscription. where encodedVapidPublicKey is an optional application server's base64 encoded VAPID public key. Error is only returned on cryptographic RNG failure or invalid option (VAPID public key) is given.
type Subscription ¶
type Subscription struct { ID string NumericID int64 Audience string // RejectUnencryptedMessage enables error when unencrypted messages (RFC8291) are pushed. RejectUnencryptedMessage bool // contains filtered or unexported fields }
Subscription is a subscription.
func (*Subscription) Authenticate ¶
func (sub *Subscription) Authenticate(authorization string) error
Authenticate verifies a VAPID authorization header. Returns an error when unauthorised.
func (*Subscription) Expire ¶
func (sub *Subscription) Expire()
Expire invalidates a subscription and lets it inactive. Inactive push resource will return 404 at Service.
func (*Subscription) GetAuth ¶
func (sub *Subscription) GetAuth() string
GetAuth returns a user-agent auth parameter; https://tools.ietf.org/html/rfc8291#section-2
func (*Subscription) GetChannel ¶
func (sub *Subscription) GetChannel() <-chan *Message
GetChannel returns a chan to receive pushed message
func (*Subscription) GetP256DH ¶
func (sub *Subscription) GetP256DH() string
GetP256DH returns a user-agent p256dh parameter; https://tools.ietf.org/html/rfc8291#section-2
func (*Subscription) GetPath ¶
func (sub *Subscription) GetPath() string
GetPath returns a HTTP path for this subscription (push message request)
func (*Subscription) GetURL ¶
func (sub *Subscription) GetURL() string
GetURL returns a HTTP URL for this subscription (push message request)
func (*Subscription) IsActive ¶
func (sub *Subscription) IsActive() bool
IsActive returns true when a subscription is still active and not expired. See also Expire()
func (*Subscription) IsRestricted ¶
func (sub *Subscription) IsRestricted() bool
IsRestricted returns true when a subscription is restricted to a specific application server with VAPID https://tools.ietf.org/html/rfc8292#section-4
type SubscriptionOption ¶
type SubscriptionOption struct {
Vapid string `json:"vapid,omitempty"`
}
SubscriptionOption is a struct represents application/webpush-options+json https://tools.ietf.org/html/rfc8292#section-4.1