Skip to content
Google Cloud Messaging for application servers implemented using the Go programming language.
Branch: master
Clone or download
Latest commit 532ebb3 Jan 25, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information. Add MIT License Mar 10, 2014 Update Jan 25, 2017
message.go removed copyright comments (see Mar 10, 2014
response.go removed copyright comments (see Mar 10, 2014
sender.go added basic unit tests Apr 1, 2014
sender_test.go added basic unit tests Apr 1, 2014


NOTE: I no longer maintain this library. Feel free to fork! :)

The Android SDK provides a nice convenience library ( that greatly simplifies the interaction between Java-based application servers and Google's GCM servers. However, Google has not provided much support for application servers implemented in languages other than Java, specifically those written in the Go programming language. The gcm package helps to fill in this gap, providing a simple interface for sending GCM messages and automatically retrying requests in case of service unavailability.


Getting Started

To install gcm, use go get:

go get

Import gcm with the following:

import ""

Sample Usage

Here is a quick sample illustrating how to send a message to the GCM server:

package main

import (


func main() {
	// Create the message to be sent.
	data := map[string]interface{}{"score": "5x1", "time": "15:10"}
	regIDs := []string{"4", "8", "15", "16", "23", "42"}
	msg := gcm.NewMessage(data, regIDs...)

	// Create a Sender to send the message.
	sender := &gcm.Sender{ApiKey: "sample_api_key"}

	// Send the message and receive the response after at most two retries.
	response, err := sender.Send(msg, 2)
	if err != nil {
		fmt.Println("Failed to send message:", err)

	/* ... */

Note for Google AppEngine users

If your application server runs on Google AppEngine, you must import the appengine/urlfetch package and create the Sender as follows:

package sample

import (


func handler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	client := urlfetch.Client(c)
	sender := &gcm.Sender{ApiKey: "sample_api_key", Http: client}

	/* ... */
You can’t perform that action at this time.