2017-06-01 07:52:01 +00:00
|
|
|
# go-fcm
|
|
|
|
|
2018-08-15 03:47:15 +00:00
|
|
|
[![GoDoc](https://godoc.org/github.com/appleboy/go-fcm?status.svg)](https://godoc.org/github.com/appleboy/go-fcm)
|
|
|
|
[![Build Status](https://travis-ci.org/appleboy/go-fcm.svg?branch=master)](https://travis-ci.org/appleboy/go-fcm)
|
|
|
|
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/go-fcm)](https://goreportcard.com/report/github.com/appleboy/go-fcmm)
|
2017-06-01 03:56:10 +00:00
|
|
|
|
2018-08-15 03:47:15 +00:00
|
|
|
This project was forked from [github.com/edganiukov/fcm](https://github.com/edganiukov/fcm).
|
2017-06-01 07:52:01 +00:00
|
|
|
|
2017-06-01 03:56:10 +00:00
|
|
|
Golang client library for Firebase Cloud Messaging. Implemented only [HTTP client](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream).
|
|
|
|
|
|
|
|
More information on [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/)
|
|
|
|
|
2017-10-24 09:00:08 +00:00
|
|
|
## Feature
|
|
|
|
|
|
|
|
* [x] Send messages to a topic
|
|
|
|
* [x] Send messages to a device list
|
|
|
|
* [x] Supports condition attribute (fcm only)
|
|
|
|
|
2017-06-01 07:52:01 +00:00
|
|
|
## Getting Started
|
|
|
|
|
2017-06-01 03:56:10 +00:00
|
|
|
To install fcm, use `go get`:
|
|
|
|
|
|
|
|
```bash
|
2017-06-01 07:52:01 +00:00
|
|
|
go get github.com/appleboy/go-fcm
|
2017-06-01 03:56:10 +00:00
|
|
|
```
|
2017-06-01 07:52:01 +00:00
|
|
|
|
2017-06-01 03:56:10 +00:00
|
|
|
or `govendor`:
|
|
|
|
|
|
|
|
```bash
|
2017-06-01 07:52:01 +00:00
|
|
|
govendor fetch github.com/appleboy/go-fcm
|
2017-06-01 03:56:10 +00:00
|
|
|
```
|
2017-06-01 07:52:01 +00:00
|
|
|
|
2017-06-01 03:56:10 +00:00
|
|
|
or other tool for vendoring.
|
|
|
|
|
2017-06-01 07:52:01 +00:00
|
|
|
## Sample Usage
|
|
|
|
|
2017-06-01 03:56:10 +00:00
|
|
|
Here is a simple example illustrating how to use FCM library:
|
2017-06-01 07:52:01 +00:00
|
|
|
|
2017-06-01 03:56:10 +00:00
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-10-24 09:00:08 +00:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/appleboy/go-fcm"
|
2017-06-01 03:56:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Create the message to be sent.
|
|
|
|
msg := &fcm.Message{
|
2017-10-24 09:00:08 +00:00
|
|
|
To: "sample_device_token",
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"foo": "bar",
|
|
|
|
},
|
|
|
|
}
|
2017-06-01 03:56:10 +00:00
|
|
|
|
|
|
|
// Create a FCM client to send the message.
|
2017-10-24 09:00:08 +00:00
|
|
|
client, err := fcm.NewClient("sample_api_key")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2017-06-01 03:56:10 +00:00
|
|
|
|
|
|
|
// Send the message and receive the response without retries.
|
|
|
|
response, err := client.Send(msg)
|
|
|
|
if err != nil {
|
2017-10-24 09:00:08 +00:00
|
|
|
log.Fatalln(err)
|
2017-06-01 03:56:10 +00:00
|
|
|
}
|
2017-10-24 09:00:08 +00:00
|
|
|
|
|
|
|
log.Printf("%#v\n", response)
|
2017-06-01 03:56:10 +00:00
|
|
|
}
|
|
|
|
```
|