Created
April 20, 2013 04:11
-
-
Save acidsound/5424720 to your computer and use it in GitHub Desktop.
GCMServer for go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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