Documentation ¶
Overview ¶
Google Cloud Messaging for application servers implemented using the Go programming language.
Index ¶
Constants ¶
const (
// GcmSendEndpoint is the endpoint for sending messages to the GCM server.
GcmSendEndpoint = "https://fcm.googleapis.com/fcm/send"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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"` 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 GCM server. See the documentation for GCM Architectural Overview for more information: http://developer.android.com/google/gcm/gcm.html#send-msg
func NewMessage ¶
NewMessage returns a new Message with the specified payload and registration IDs.
type Response ¶
type Response struct { MulticastID int64 `json:"multicast_id"` Success int `json:"success"` Failure int `json:"failure"` CanonicalIDs int `json:"canonical_ids"` Results []Result `json:"results"` }
Response represents the GCM server's response to the application server's sent message. See the documentation for GCM Architectural Overview for more information: http://developer.android.com/google/gcm/gcm.html#send-msg
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.
type Sender ¶
Sender abstracts the interaction between the application server and the GCM server. The developer must obtain an API key from the Google APIs Console page and pass it to the Sender so that it can perform authorized requests on the application server's behalf. To send a message to one or more devices use the Sender's Send or SendNoRetry methods.
If the Http field is nil, a zeroed http.Client will be allocated and used to send messages. If your application server runs on Google AppEngine, you must use the "appengine/urlfetch" package to create the *http.Client as follows:
func handler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) client := urlfetch.Client(c) sender := &gcm.Sender{ApiKey: key, Http: client} /* ... */ }
func (*Sender) Send ¶
Send sends a message to the GCM server, 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").
Note that messages are retried using exponential backoff, and as a result, this method may block for several seconds.