Documentation
¶
Overview ¶
Package gcm is 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://gcm-http.googleapis.com/gcm/send"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client 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 method.
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} /* ... */ }
type Message ¶
type Message struct { To string `json:"to"` RegistrationIDs []string `json:"registration_ids,omitempty"` CollapseKey string `json:"collapse_key,omitempty"` Priority string `json:"priority,omitempty"` ContentAvailable bool `json:"content_available,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"` Data map[string]interface{} `json:"data,omitempty"` Notification *Notification `json:"notification,omitempty"` }
Message contains all fields that can be sent to the GCM API. Not all fields should be set, it's recommended to read the reference before sending anything at https://developers.google.com/cloud-messaging/http-server-ref
type Notification ¶
type Notification struct { Title string `json:"title,omitempty"` Body string `json:"body,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"` 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 containts all notification fields as defined in the GCM API reference
type Response ¶
type Response struct { MessageID int `json:"message_id,omitempty"` Error errorString `json:"error,omitempty"` MulticastID int `json:"multicast_id,omitempty"` Success int `json:"success,omitempty"` Failure int `json:"failure,omitempty"` CanonicalIDs int `json:"canonical_ids,omitempty"` Results []Result `json:"results,omitempty"` }
Response represents the GCM server's response to the application server's sent message. See the documentation for more information: https://developers.google.com/cloud-messaging/http-server-ref#interpret-downstream