push

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2016 License: MIT Imports: 11 Imported by: 49

Documentation

Overview

Package push sends notifications over HTTP/2 to Apple's Push Notification Service.

Index

Constants

View Source
const (
	Development = "https://api.development.push.apple.com"
	Production  = "https://api.push.apple.com"
)

Apple host locations for configuring Service.

Variables

View Source
var (
	// These could be checked prior to sending the request to Apple.
	ErrPayloadEmpty    = errors.New("PayloadEmpty")
	ErrPayloadTooLarge = errors.New("PayloadTooLarge")

	// Device token errors.
	ErrMissingDeviceToken = errors.New("MissingDeviceToken")
	ErrBadDeviceToken     = errors.New("BadDeviceToken")
	ErrTooManyRequests    = errors.New("TooManyRequests")

	// Header errors.
	ErrBadMessageID      = errors.New("BadMessageID")
	ErrBadExpirationDate = errors.New("BadExpirationDate")
	ErrBadPriority       = errors.New("BadPriority")
	ErrBadTopic          = errors.New("BadTopic")

	// Certificate and topic errors.
	ErrBadCertificate            = errors.New("BadCertificate")
	ErrBadCertificateEnvironment = errors.New("BadCertificateEnvironment")
	ErrForbidden                 = errors.New("Forbidden")
	ErrMissingTopic              = errors.New("MissingTopic")
	ErrTopicDisallowed           = errors.New("TopicDisallowed")
	ErrUnregistered              = errors.New("Unregistered")
	ErrDeviceTokenNotForTopic    = errors.New("DeviceTokenNotForTopic")

	// These errors should never happen when using Push.
	ErrDuplicateHeaders = errors.New("DuplicateHeaders")
	ErrBadPath          = errors.New("BadPath")
	ErrMethodNotAllowed = errors.New("MethodNotAllowed")

	// Fatal server errors.
	ErrIdleTimeout         = errors.New("IdleTimeout")
	ErrShutdown            = errors.New("Shutdown")
	ErrInternalServerError = errors.New("InternalServerError")
	ErrServiceUnavailable  = errors.New("ServiceUnavailable")
)

Service error responses.

Functions

func IsDeviceTokenValid added in v0.3.0

func IsDeviceTokenValid(s string) bool

IsDeviceTokenValid checks if s is a hexadecimal token of the correct length.

Types

type Error added in v0.3.0

type Error struct {
	Reason    error
	Status    int // http StatusCode
	Timestamp time.Time
}

Error responses from Apple

func (*Error) Error added in v0.3.0

func (e *Error) Error() string

type Headers

type Headers struct {
	// ID for the notification. Apple generates one if omitted.
	// This should be a UUID with 32 lowercase hexadecimal digits.
	// TODO: use a UUID type.
	ID string

	// Apple will retry delivery until this time. The default behavior only tries once.
	Expiration time.Time

	// Allow Apple to group messages together to reduce power consumption.
	// By default messages are sent immediately.
	LowPriority bool
}

Headers sent with a push to control the notification (optional)

type Service

type Service struct {
	Host   string
	Client *http.Client
	Topic  string
}

Service is the Apple Push Notification Service that you send notifications to.

func NewService added in v0.5.0

func NewService(host string, cert tls.Certificate) (*Service, error)

NewService sets up an HTTP/2 client for a certificate and extracts the Topic from the certificate. If you need to do something custom, you can always override the fields in Service, e.g. to specify your own http.Client.

func (*Service) Push

func (s *Service) Push(deviceToken string, headers *Headers, payload interface{}) (string, error)

Push notification to APN service after performing serialization.

func (*Service) PushBytes

func (s *Service) PushBytes(deviceToken string, headers *Headers, payload []byte) (string, error)

PushBytes notification to APN service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL