2016-05-31 01:02:34 +03:00
|
|
|
# go-fcm
|
|
|
|
Firebase Cloud Messaging ( FCM ) Library using golang ( Go )
|
|
|
|
|
|
|
|
This library uses HTTP/JSON Firebase Cloud Messaging connection server protocol
|
2016-05-31 01:03:33 +03:00
|
|
|
|
|
|
|
|
2016-06-21 12:02:51 +03:00
|
|
|
- features
|
|
|
|
|
|
|
|
* send messages to a topic
|
|
|
|
* send messages to a device list
|
|
|
|
* message can be a notification or data payload
|
|
|
|
|
2016-06-21 12:03:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
---- in progress
|
2016-06-21 12:02:51 +03:00
|
|
|
* retry
|
|
|
|
* instance id features
|
2016-06-21 12:03:50 +03:00
|
|
|
|
2016-06-21 12:02:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
|
|
|
```
|
|
|
|
go get github.com/NaySoftware/go-fcm
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Example - Send to A topic
|
|
|
|
|
|
|
|
```golang
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/NaySoftware/go-fcm"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
key = "YOUR-KEY"
|
|
|
|
topic = "/topics/someTopic"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
data := map[string]string{
|
|
|
|
"msg": "Hello World1",
|
|
|
|
"sum": "Happy Day",
|
|
|
|
}
|
|
|
|
|
|
|
|
c := fcm.NewFcmClient(key)
|
|
|
|
c.NewFcmMsgTo(topic, data)
|
|
|
|
|
|
|
|
status, err := c.Send(1)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
status.PrintResults()
|
|
|
|
} else {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2016-06-21 12:18:25 +03:00
|
|
|
# Example - Send to a list of Devices (tokens)
|
2016-06-21 12:02:51 +03:00
|
|
|
|
|
|
|
```golang
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/NaySoftware/go-fcm"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
key = "YOUR-KEY"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
data := map[string]string{
|
|
|
|
"msg": "Hello World1",
|
|
|
|
"sum": "Happy Day",
|
|
|
|
}
|
|
|
|
|
|
|
|
ids := []string{
|
|
|
|
"token1",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
xds := []string{
|
|
|
|
"token5",
|
|
|
|
"token6",
|
|
|
|
"token7",
|
|
|
|
}
|
|
|
|
|
|
|
|
c := fcm.NewFcmClient(key)
|
|
|
|
c.NewFcmRegIdsMsg(ids, data)
|
|
|
|
c.AppendDevices(xds)
|
|
|
|
|
|
|
|
status, err := c.Send(1)
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
status.PrintResults()
|
|
|
|
} else {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|