push

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2016 License: MIT Imports: 10 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.

Variables

View Source
var (
	ErrPayloadEmpty    = errors.New("the message payload was empty")
	ErrPayloadTooLarge = errors.New("the message payload was too large")

	ErrMissingDeviceToken = errors.New("device token was not specified")
	ErrBadDeviceToken     = errors.New("bad device token")
	ErrTooManyRequests    = errors.New("too many requests were made consecutively to the same device token")

	ErrBadMessageID      = errors.New("the ID header value is bad")
	ErrBadExpirationDate = errors.New("the Expiration header value is bad")
	ErrBadPriority       = errors.New("the apns-priority value is bad")
	ErrBadTopic          = errors.New("the Topic header was invalid")

	ErrBadCertificate            = errors.New("the certificate was bad")
	ErrBadCertificateEnvironment = errors.New("certificate was for the wrong environment")
	ErrForbidden                 = errors.New("there was an error with the certificate")

	ErrMissingTopic           = errors.New("the Topic header of the request was not specified and was required")
	ErrTopicDisallowed        = errors.New("pushing to this topic is not allowed")
	ErrUnregistered           = errors.New("device token is inactive for the specified topic")
	ErrDeviceTokenNotForTopic = errors.New("device token does not match the specified topic")

	ErrDuplicateHeaders = errors.New("one or more headers were repeated")
	ErrBadPath          = errors.New("the request contained a bad :path")
	ErrMethodNotAllowed = errors.New("the specified :method was not POST")

	ErrIdleTimeout         = errors.New("idle time out")
	ErrShutdown            = errors.New("the server is shutting down")
	ErrInternalServerError = errors.New("an internal server error occurred")
	ErrServiceUnavailable  = errors.New("the service is unavailable")

	ErrBadRequest = errors.New("bad request")
	ErrUnknown    = errors.New("unknown error")
)

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.

func NewClient

func NewClient(cert tls.Certificate) *http.Client

NewClient sets up an HTTPS client for a certificate. If you need to do something custom, you can always specify your own http.Client for Service.

Types

type Error added in v0.3.0

type Error struct {
	Err         error
	Timestamp   time.Time
	DeviceToken string
}

Error with a timestamp

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 ommitted.
	// 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 to together to reduce power consumption.
	// By default messages are sent immediately.
	LowPriority bool

	// Topic for certificates with multiple topics.
	Topic string
}

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

type Service

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

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

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