gcm

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT, MIT Imports: 5 Imported by: 2

README

GCM & FCM

This package is forked from alexjlockwood/gcm since that project is no longer maintained.

This package providies a interface for sending GCM/FCM messages and automatically retrying requests in case of service unavailability.

Documentation

Index

Constants

View Source
const (
	// FCMSendEndpoint is the endpoint for sending message to the Firebase Cloud Messaging (FCM) server.
	// See more on https://firebase.google.com/docs/cloud-messaging/server
	FCMSendEndpoint = "https://fcm.googleapis.com/fcm/send"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ApiKey string
	URL    string
	Http   *http.Client
}

Client abstracts the interaction between the application server and the FCM server. 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 methods.

func NewClient

func NewClient(urlString, apiKey string) (*Client, error)

NewClient returns a new sender with the given URL and apiKey. If one of input is empty or URL is malformed, returns error. It sets http.DefaultHTTP client for http connection to server. If you need our own configuration overwrite it.

func (*Client) Send

func (c *Client) Send(msg *Message) (*Response, error)

Send sends a message to the FCM server without retrying in case of service unavailability. A non-nil error is returned if a non-recoverable error occurs (i.e. if the response status is not "200 OK").

type Message

type Message struct {
	RegistrationIDs       []string               `json:"registration_ids"`
	CollapseKey           string                 `json:"collapse_key,omitempty"`
	Data                  map[string]interface{} `json:"data,omitempty"`
	DelayWhileIdle        bool                   `json:"delay_while_idle,omitempty"`
	TimeToLive            int                    `json:"time_to_live,omitempty"`
	Priority              string                 `json:"priority,omitempty"`
	RestrictedPackageName string                 `json:"restricted_package_name,omitempty"`
	DryRun                bool                   `json:"dry_run,omitempty"`
}

Message is used by the application server to send a message to the FCM server. See the documentation for FCM Architectural Overview for more information: https://firebase.google.com/docs/cloud-messaging/http-server-ref

func NewMessage

func NewMessage(data map[string]interface{}, regIDs ...string) *Message

NewMessage returns a new Message with the specified payload and registration IDs.

type Response

type Response struct {
	MulticastID  int64    `json:"multicast_id"`
	CanonicalIDs int      `json:"canonical_ids"`
	Results      []Result `json:"results"`
}

Response represents the FCM server's response to the application server's sent message. See the documentation for FCM Architectural Overview for more information: https://firebase.google.com/docs/cloud-messaging/http-server-ref

type Result

type Result struct {
	MessageID      string `json:"message_id"`
	RegistrationID string `json:"registration_id"`
	Error          string `json:"error"`
}

Result represents the status of a processed message.

Jump to

Keyboard shortcuts

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