Skip to content

Instantly share code, notes, and snippets.

@acidsound
Created April 20, 2013 04:11
Show Gist options
  • Save acidsound/5424720 to your computer and use it in GitHub Desktop.
Save acidsound/5424720 to your computer and use it in GitHub Desktop.
GCMServer for go
package main
import (
"net/http"
gcm "github.com/googollee/go-gcm"
"fmt"
)
func main() {
http.HandleFunc("/sendMessage", sendMessageHandler)
http.ListenAndServe("localhost:8000", nil)
}
func sendMessageHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
fmt.Println("message received")
client := gcm.New("AIzaSyBDJRr6aXjDe1dF9orT1biHic3VdECsIGA")
load := gcm.NewMessage(r.FormValue("target"))
load.SetPayload("data", r.FormValue("message"))
fmt.Println(r.FormValue("message"))
resp, err := client.Send(load)
fmt.Printf("id: %+v\n", resp)
fmt.Println("err:", err)
fmt.Println("err index:", resp.ErrorIndexes())
fmt.Println("reg index:", resp.RefreshIndexes())
fmt.Fprint(w, "done")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment