Exemple #1
0
// onMessage receives messages, logs them, and echoes a response.
func onMessage(cm gcm.CcsMessage) error {
	toylog.Infoln("Message, from:", cm.From, "with:", cm.Data)
	// Echo the message with a tag.
	cm.Data["echoed"] = true
	m := gcm.HttpMessage{To: cm.From, Data: cm.Data}
	r, err := gcm.SendHttp(*serverKey, m)
	if err != nil {
		toylog.Errorln("Error sending message.", err)
		return err
	}
	toylog.Infof("Sent message. %+v -> %+v", m, r)
	return nil
}
Exemple #2
0
// onMessage receives messages, logs them, and echoes a response.
func onMessage(from string, d gcm.Data) error {
	toylog.Infoln("Message, from:", from, "with:", d)
	// Echo the message with a tag.
	d["echoed"] = true
	m := gcm.HttpMessage{To: from, Data: d}
	r, err := gcm.SendHttp(*serverKey, m)
	if err != nil {
		toylog.Errorln("Error sending message.", err)
		return err
	}
	toylog.Infof("Sent message. %+v -> %+v", m, r)
	return nil
}