Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

gamegos/gcmlib

Repository files navigation

gcmlib

Build Status

Golang Google Cloud Messaging(GCM) library.

Installation

$ go get github.com/gamegos/gcmlib

Then

import "github.com/gamegos/gcmlib"

Example Usage

package main

import (
	"fmt"

	gcm "github.com/gamegos/gcmlib"
)

func main() {
	client := gcm.NewClient(gcm.Config{
	    APIKey:     "your-gcm-api-key",
	    MaxRetries: 4,
	})

	message := &gcm.Message{
	    RegistrationIDs: []string{"registrationID1", "registrationID2"},
	    Notification: &gcm.Notification{
	        Title: "Example GCM message",
	        Body:  "Hello world",
	    },
	    Data: map[string]string{
	        "customKey": "custom value",
	    },
	}

	response, err := client.Send(message)
	if err != nil {
	    fmt.Printf("Error: %#v\n", err)
	    return
	}

	fmt.Printf("Success: %#v\n", response)
}

Tests

gcmlib provides both unit and integration tests.

To run unit tests:

$ go test

To run integration tests you need to pass your android application's GCM api key and a registration id for this application.

$ go test -v -tags=integration -key=$GCM_KEY -regid=$GCM_REGID

By default, push messages in integration tests will only be sent to the google servers in dry_run mode. If you actually want to deliver messages to the device, set -dry=false

$ go test -v -tags=integration -key=$GCM_KEY -regid=$GCM_REGID -dry=false

License

MIT. See LICENSE.

About

Google Cloud Messaging (GCM) Go client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages