Documentation ¶
Index ¶
- Constants
- type APS
- type Alert
- type Client
- type ClientMock
- func (m *ClientMock) MinimockFinish()
- func (m *ClientMock) MinimockSendDone() bool
- func (m *ClientMock) MinimockSendInspect()
- func (m *ClientMock) MinimockWait(timeout mm_time.Duration)
- func (mmSend *ClientMock) Send(ctx context.Context, n *Notification) (err error)
- func (mmSend *ClientMock) SendAfterCounter() uint64
- func (mmSend *ClientMock) SendBeforeCounter() uint64
- type ClientMockSendExpectation
- type ClientMockSendParams
- type ClientMockSendResults
- type ClientOption
- type Error
- type ErrorReason
- type JWTConfig
- type Notification
- type Payload
- type PushType
- type Response
- type RoundTripperJWTDecorator
- type SimpleClient
- type Token
Constants ¶
const ( DevelopmentGateway = apns2.HostDevelopment ProductionGateway = apns2.HostProduction )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APS ¶
type APS struct { // Alert dictionary. Alert Alert `json:"alert,omitempty"` // Badge to display on the app icon. Badge int `json:"badge,omitempty"` // Sound is the name of a sound file to play as an alert. Sound string `json:"sound,omitempty"` // Content available apps launched in the background or resumed. ContentAvailable int `json:"content-available,omitempty"` // Category identifier for custom actions in iOS 8 or newer. Category string `json:"category,omitempty"` // ThreadID presents the app-specific identifier for grouping notifications. ThreadID string `json:"thread-id,omitempty"` // MutableContent presents the flag that lets user’s device know // that it should run the corresponding service app extension (if the value equals 1). MutableContent int `json:"mutable-content,omitempty"` }
APS is Apple's reserved payload. easyjson:json
func (APS) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (APS) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*APS) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*APS) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type Alert ¶
type Alert struct { Title string `json:"title,omitempty"` Body string `json:"body,omitempty"` TitleLocKey string `json:"title-loc-key,omitempty"` TitleLocArgs []string `json:"title-loc-args,omitempty"` ActionLocKey string `json:"action-loc-key,omitempty"` LocKey string `json:"loc-key,omitempty"` LocArgs []string `json:"loc-args,omitempty"` LaunchImage string `json:"launch-image,omitempty"` }
Alert represents alert dictionary. easyjson:json
func (Alert) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Alert) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Alert) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Alert) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type Client ¶
type Client interface {
Send(ctx context.Context, n *Notification) error
}
Client describes methods used to send apns notifications.
type ClientMock ¶
type ClientMock struct { SendMock mClientMockSend // contains filtered or unexported fields }
ClientMock implements Client
func NewClientMock ¶
func NewClientMock(t minimock.Tester) *ClientMock
NewClientMock returns a mock for Client
func (*ClientMock) MinimockFinish ¶
func (m *ClientMock) MinimockFinish()
MinimockFinish checks that all mocked methods have been called the expected number of times
func (*ClientMock) MinimockSendDone ¶
func (m *ClientMock) MinimockSendDone() bool
MinimockSendDone returns true if the count of the Send invocations corresponds the number of defined expectations
func (*ClientMock) MinimockSendInspect ¶
func (m *ClientMock) MinimockSendInspect()
MinimockSendInspect logs each unmet expectation
func (*ClientMock) MinimockWait ¶
func (m *ClientMock) MinimockWait(timeout mm_time.Duration)
MinimockWait waits for all mocked methods to be called the expected number of times
func (*ClientMock) Send ¶
func (mmSend *ClientMock) Send(ctx context.Context, n *Notification) (err error)
Send implements Client
func (*ClientMock) SendAfterCounter ¶
func (mmSend *ClientMock) SendAfterCounter() uint64
SendAfterCounter returns a count of finished ClientMock.Send invocations
func (*ClientMock) SendBeforeCounter ¶
func (mmSend *ClientMock) SendBeforeCounter() uint64
SendBeforeCounter returns a count of ClientMock.Send invocations
type ClientMockSendExpectation ¶
type ClientMockSendExpectation struct { Counter uint64 // contains filtered or unexported fields }
ClientMockSendExpectation specifies expectation struct of the Client.Send
func (*ClientMockSendExpectation) Then ¶
func (e *ClientMockSendExpectation) Then(err error) *ClientMock
Then sets up Client.Send return parameters for the expectation previously defined by the When method
type ClientMockSendParams ¶
type ClientMockSendParams struct {
// contains filtered or unexported fields
}
ClientMockSendParams contains parameters of the Client.Send
type ClientMockSendResults ¶
type ClientMockSendResults struct {
// contains filtered or unexported fields
}
ClientMockSendResults contains results of the Client.Send
type ClientOption ¶
type ClientOption func(c *SimpleClient) error
ClientOption defines athe APNS SimpleClient option.
func WithGateway ¶
func WithGateway(endpoint string) ClientOption
WithGateway specifies custom APN endpoint. Useful for test propose.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient sets custom HTTP SimpleClient.
func WithJWTAuthorization ¶
func WithJWTAuthorization(cfg JWTConfig) ClientOption
WithJWTAuthorization enables JWT authorization for apns requests.
func WithTimeout ¶
func WithTimeout(t time.Duration) ClientOption
WithTimeout sets HTTP SimpleClient timeout.
type ErrorReason ¶
type ErrorReason string
ErrorReason API error reasons https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns
const ( ReasonExpiredProviderToken ErrorReason = "ExpiredProviderToken" ReasonBadDeviceToken ErrorReason = "BadDeviceToken" ReasonCodeUnregistered ErrorReason = "Unregistered" )
type Notification ¶
type Notification struct { // An optional canonical UUID that identifies the notification. The // canonical form is 32 lowercase hexadecimal digits, displayed in five // groups separated by hyphens in the form 8-4-4-4-12. An example UUID is as // follows: // // 123e4567-e89b-12d3-a456-42665544000 // // If you don't set this, a new UUID is created by APNs and returned in the // response. ApnsID string // A string which allows multiple notifications with the same collapse // identifier to be displayed to the user as a single notification. The // value should not exceed 64 bytes. CollapseID string // A string containing hexadecimal bytes of the device token for the target // device. DeviceToken string // The topic of the remote notification, which is typically the bundle ApnsID // for your app. The certificate you create in the Apple Developer Member // Center must include the capability for this topic. If your certificate // includes multiple topics, you must specify a value for this header. If // you omit this header and your APNs certificate does not specify multiple // topics, the APNs server uses the certificate’s Subject as the default // topic. Topic string // An optional time at which the notification is no longer valid and can be // discarded by APNs. If this value is in the past, APNs treats the // notification as if it expires immediately and does not store the // notification or attempt to redeliver it. If this value is left as the // default (ie, Expiration.IsZero()) an expiration header will not added to // the http request. Expiration time.Time // The priority of the notification. Specify ether apns.PriorityHigh (10) or // apns.PriorityLow (5) If you don't set this, the APNs server will set the // priority to 10. Priority int // A byte array containing the JSON-encoded payload of this push notification. // Refer to "The Remote Notification Payload" section in the Apple Local and // Remote Notification Programming Guide for more info. Payload Payload // The pushtype of the push notification. If this values is left as the // default an apns-push-type header with value 'alert' will be added to the // http request. PushType PushType }
type Payload ¶
type Payload struct { APS APS `json:"aps"` Data json.RawMessage `json:"data"` }
Payload repsresents a data structure for APN notification. easyjson:json
func (Payload) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Payload) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Payload) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Payload) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type PushType ¶
type PushType string
PushType defines the value for the apns-push-type header
const ( // PushTypeAlert is used for notifications that trigger a user interaction — // for example, an alert, badge, or sound. If you set this push type, the // apns-topic header field must use your app’s bundle ApnsID as the topic. The // alert push type is required on watchOS 6 and later. It is recommended on // macOS, iOS, tvOS, and iPadOS. PushTypeAlert PushType = "alert" // PushTypeBackground is used for notifications that deliver content in the // background, and don’t trigger any user interactions. If you set this push // type, the apns-topic header field must use your app’s bundle ApnsID as the // topic. The background push type is required on watchOS 6 and later. It is // recommended on macOS, iOS, tvOS, and iPadOS. PushTypeBackground PushType = "background" // PushTypeVOIP is used for notifications that provide information about an // incoming Voice-over-IP (VoIP) call. If you set this push type, the // apns-topic header field must use your app’s bundle ApnsID with .voip appended // to the end. If you’re using certificate-based authentication, you must // also register the certificate for VoIP services. The voip push type is // not available on watchOS. It is recommended on macOS, iOS, tvOS, and // iPadOS. PushTypeVOIP PushType = "voip" // PushTypeComplication is used for notifications that contain update // information for a watchOS app’s complications. If you set this push type, // the apns-topic header field must use your app’s bundle ApnsID with // .complication appended to the end. If you’re using certificate-based // authentication, you must also register the certificate for WatchKit // services. The complication push type is recommended for watchOS and iOS. // It is not available on macOS, tvOS, and iPadOS. PushTypeComplication PushType = "complication" // PushTypeFileProvider is used to signal changes to a File Provider // extension. If you set this push type, the apns-topic header field must // use your app’s bundle ApnsID with .pushkit.fileprovider appended to the end. // The fileprovider push type is not available on watchOS. It is recommended // on macOS, iOS, tvOS, and iPadOS. PushTypeFileProvider PushType = "fileprovider" // PushTypeMDM is used for notifications that tell managed devices to // contact the MDM server. If you set this push type, you must use the topic // from the UID attribute in the subject of your MDM push certificate. PushTypeMDM PushType = "mdm" )
type Response ¶
type Response struct {
Reason ErrorReason `json:"reason"`
}
easyjson:json
func (Response) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Response) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Response) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Response) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type RoundTripperJWTDecorator ¶
type RoundTripperJWTDecorator struct { Parent http.RoundTripper Token *Token }
RoundTripperJWTDecorator an implementation of http.RoundTripper interface with ability to specify authorization JWT token for each request.
type SimpleClient ¶
type SimpleClient struct {
// contains filtered or unexported fields
}
SimpleClient represents the Apple Push Notification Service that you send notifications to.
func MustNewClient ¶
func MustNewClient(opts ...ClientOption) *SimpleClient
MustNewClient creates new APNS client based on defined Options.
func (*SimpleClient) Send ¶
func (c *SimpleClient) Send(ctx context.Context, n *Notification) error
Send sends Notification to the APN service.