Documentation
¶
Overview ¶
Package expox is a Go SDK for the Expo Push Notification Service.
It provides a production-ready client with batching, gzip compression, rate limiting, 429 retry with exponential backoff, and receipt polling.
Types live in expox/types, limiters in expox/limiter. For convenience, commonly used types are aliased here so callers can use expox.Message instead of types.Message.
Index ¶
- Constants
- Variables
- func ChunkMessages(msgs []Message, n int) [][]Message
- func ChunkReceiptIDs(ids []string, n int) [][]string
- func IsValidPushToken(token string) bool
- func ValidatePayload(msg Message) error
- type APIError
- type APIErrorEntry
- type BatchResult
- type Client
- func (c *Client) GetReceipts(ctx context.Context, ticketIDs []string) (map[string]Receipt, error)
- func (c *Client) ProcessReceipts(ctx context.Context, ticketIDs []string) ([]ReceiptResult, error)
- func (c *Client) Send(ctx context.Context, messages []Message) (*BatchResult, error)
- func (c *Client) SendBroadcast(ctx context.Context, tokens []string, msg Message) (*BatchResult, error)
- func (c *Client) SendSingle(ctx context.Context, msg Message) (*SendResult, error)
- type ErrorCode
- type InterruptionLevel
- type Limiter
- type Message
- type Option
- func WithAccessToken(token string) Option
- func WithBatchSize(size int) Option
- func WithGzipThreshold(n int) Option
- func WithHTTPClient(hc *http.Client) Option
- func WithHost(host string) Option
- func WithLimiter(l limiter.Limiter) Option
- func WithMaxConcurrent(n int) Option
- func WithMaxRetries(n int) Option
- func WithReceiptBatchSize(size int) Option
- func WithRetryMinTimeout(d time.Duration) Option
- type Priority
- type Receipt
- type ReceiptResult
- type RichContent
- type SendResult
- type Sound
- type Ticket
Constants ¶
const ( Version = "0.1.0" DefaultHost = "https://exp.host" DefaultBasePath = "/--/api/v2" DefaultBatchSize = 100 DefaultReceiptBatchSize = 300 DefaultMaxConcurrent = 6 DefaultHTTPTimeout = 30 * time.Second DefaultRetryMinTimeout = 1 * time.Second DefaultMaxRetries = 3 DefaultGzipThreshold = 1024 DefaultRateLimit = 600 DefaultBurst = 100 // MaxPayloadSize is the maximum total notification payload size (bytes). MaxPayloadSize = 4096 )
Variables ¶
var ( DefaultSound = types.DefaultSound ErrDeviceNotRegistered = types.ErrDeviceNotRegistered ErrInvalidCredentials = types.ErrInvalidCredentials ErrMessageTooBig = types.ErrMessageTooBig ErrMessageRateExceeded = types.ErrMessageRateExceeded ErrMismatchSenderId = types.ErrMismatchSenderId ErrInvalidProviderToken = types.ErrInvalidProviderToken ErrProviderError = types.ErrProviderError )
Re-export constants and constructors.
Functions ¶
func ChunkMessages ¶
ChunkMessages splits messages into chunks of at most size n.
func ChunkReceiptIDs ¶
ChunkReceiptIDs splits receipt IDs into chunks of at most size n.
func IsValidPushToken ¶
IsValidPushToken checks whether the token is a valid Expo push token.
func ValidatePayload ¶
ValidatePayload checks that a message's JSON payload does not exceed MaxPayloadSize.
Types ¶
type APIErrorEntry ¶
type APIErrorEntry = types.APIErrorEntry
type BatchResult ¶
type BatchResult = types.BatchResult
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an Expo push notification client.
func (*Client) GetReceipts ¶
GetReceipts fetches push notification delivery receipts by ticket IDs. IDs are automatically chunked into batches.
func (*Client) ProcessReceipts ¶
ProcessReceipts fetches receipts and returns structured results. Useful for identifying tokens to remove (DeviceNotRegistered) or credentials to refresh (InvalidCredentials).
func (*Client) Send ¶
Send sends push notifications in batches concurrently. Concurrency is bounded by the Client's connection semaphore (MaxConcurrent). Partial batch failures are collected into the result rather than aborting.
func (*Client) SendBroadcast ¶
func (c *Client) SendBroadcast(ctx context.Context, tokens []string, msg Message) (*BatchResult, error)
SendBroadcast sends the same notification content to many recipients concurrently. Tokens are batched and sent using Expo's array-to field for efficiency.
func (*Client) SendSingle ¶
SendSingle sends a push notification to a single recipient.
type InterruptionLevel ¶
type InterruptionLevel = types.InterruptionLevel
type Option ¶
type Option func(*Client)
Option configures the Client.
func WithAccessToken ¶
func WithBatchSize ¶
func WithGzipThreshold ¶
func WithHTTPClient ¶
func WithLimiter ¶
func WithMaxConcurrent ¶
func WithMaxRetries ¶
func WithReceiptBatchSize ¶
func WithRetryMinTimeout ¶
type ReceiptResult ¶
type ReceiptResult = types.ReceiptResult
type RichContent ¶
type RichContent = types.RichContent
type SendResult ¶
type SendResult = types.SendResult
Directories
¶
| Path | Synopsis |
|---|---|
|
Package expofx provides Uber Fx integration for expox.
|
Package expofx provides Uber Fx integration for expox. |
|
Package limiter provides rate limiting for the Expo Push API.
|
Package limiter provides rate limiting for the Expo Push API. |
|
redis
Package redis provides a distributed rate limiter for expox backed by Redis.
|
Package redis provides a distributed rate limiter for expox backed by Redis. |