Documentation ¶
Index ¶
Constants ¶
const (
// DefaultEndpoint contains endpoint URL of FCM service.
DefaultEndpoint = "https://fcm.googleapis.com/fcm/send"
)
Variables ¶
var ( // ErrInvalidMessage occurs if push notitication message is nil. ErrInvalidMessage = errors.New("message is invalid") // ErrInvalidTarget occurs if message topic is empty. ErrInvalidTarget = errors.New("topic is invalid or registration ids are not set") // ErrToManyRegIDs occurs when registration ids more then 1000. ErrToManyRegIDs = errors.New("too many registrations ids") // ErrInvalidTimeToLive occurs if TimeToLive more then 2419200. ErrInvalidTimeToLive = errors.New("messages time-to-live is invalid") )
var ( // ErrMissingRegistration occurs if registration token is not set. ErrMissingRegistration = errors.New("missing registration token") // ErrInvalidRegistration occurs if registration token is invalid. ErrInvalidRegistration = errors.New("invalid registration token") // ErrNotRegistered occurs when application was deleted from device and // token is not registered in FCM. ErrNotRegistered = errors.New("unregistered device") // ErrInvalidPackageName occurs if package name in message is invalid. ErrInvalidPackageName = errors.New("invalid package name") // ErrMismatchSenderID occurs when application has a new registration token. ErrMismatchSenderID = errors.New("mismatched sender id") // ErrMessageTooBig occurs when message is too big. ErrMessageTooBig = errors.New("message is too big") // ErrInvalidDataKey occurs if data key is invalid. ErrInvalidDataKey = errors.New("invalid data key") // ErrInvalidTTL occurs when message has invalid TTL. ErrInvalidTTL = errors.New("invalid time to live") // to retry after this error. ErrUnavailable = connectionError("timeout") // ErrInternalServerError is internal FCM error. It makes sense to retry // after this error. ErrInternalServerError = serverError("internal server error") // ErrDeviceMessageRateExceeded occurs when client sent to many requests to // the device. ErrDeviceMessageRateExceeded = errors.New("device message rate exceeded") // ErrTopicsMessageRateExceeded occurs when client sent to many requests to // the topics. ErrTopicsMessageRateExceeded = errors.New("topics message rate exceeded") )
var ( // ErrInvalidAPIKey occurs if API key is not set. ErrInvalidAPIKey = errors.New("client API Key is invalid") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client abstracts the interaction between the application server and the FCM server via HTTP protocol. The developer must obtain an API key from the Google APIs Console page and pass it to the `Client` so that it can perform authorized requests on the application server's behalf. To send a message to one or more devices use the Client's Send.
If the `HTTP` field is nil, a zeroed http.Client will be allocated and used to send messages.
func NewClient ¶
NewClient creates new Firebase Cloud Messaging Client based on API key and with default endpoint and http client.
type Message ¶
type Message struct { Token string `json:"to,omitempty"` RegistrationIDs []string `json:"registration_ids,omitempty"` Condition string `json:"condition,omitempty"` CollapseKey string `json:"collapse_key,omitempty"` Priority string `json:"priority,omitempty"` ContentAvailable bool `json:"content_available,omitempty"` MutableContent bool `json:"mutable_content,omitempty"` DelayWhileIdle bool `json:"delay_while_idle,omitempty"` TimeToLive int `json:"time_to_live,omitempty"` RestrictedPackageName string `json:"restricted_package_name,omitempty"` DeliveryReceiptRequested bool `json:"delivery_receipt_requested,omitempty"` DryRun bool `json:"dry_run,omitempty"` Notification *Notification `json:"notification,omitempty"` Data map[string]interface{} `json:"data,omitempty"` }
Message represents list of targets, options, and payload for HTTP JSON messages.
type Notification ¶
type Notification struct { Title string `json:"title,omitempty"` Body string `json:"body,omitempty"` AndroidChannelId string `json:"android_channel_id,omitempty"` Icon string `json:"icon,omitempty"` Sound string `json:"sound,omitempty"` Badge string `json:"badge,omitempty"` Tag string `json:"tag,omitempty"` Color string `json:"color,omitempty"` ClickAction string `json:"click_action,omitempty"` Subtitle string `json:"subtitle,omitempty"` BodyLocKey string `json:"body_loc_key,omitempty"` BodyLocArgs string `json:"body_loc_args,omitempty"` TitleLocKey string `json:"title_loc_key,omitempty"` TitleLocArgs string `json:"title_loc_args,omitempty"` }
Notification specifies the predefined, user-visible key-value pairs of the notification payload.
type Option ¶ added in v0.2.0
Option configurates Client with defined option.
func WithEndpoint ¶ added in v0.2.0
WithEndpoint returns Option to configure FCM Endpoint.
func WithHTTPClient ¶ added in v0.2.0
WithHTTPClient returns Option to configure HTTP Client.
type Response ¶
type Response struct { MulticastID int64 `json:"multicast_id"` Success int `json:"success"` Failure int `json:"failure"` CanonicalIDs int `json:"canonical_ids"` StatusCode int `json:"error_code"` Results []Result `json:"results"` }
Response represents the FCM server's response to the application server's sent message.
type Result ¶
type Result struct { MessageID string `json:"message_id"` RegistrationID string `json:"registration_id"` Error error `json:"error"` }
Result represents the status of a processed message.
func (*Result) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler interface.
func (Result) Unregistered ¶
Unregistered checks if the device token is unregistered, according to response from FCM server. Useful to determine if app is uninstalled.