i am doing ionic apps, using cordova fcm plugin i get the device token.Now i want send the push notification from go server.please help me how use go as the fcm server.I need some implementation example
package main
import (
"fmt"
"github.com/NaySoftware/go-fcm"
)
const (
serverKey = "YOUR-KEY"
)
func main() {
var NP fcm.NotificationPayload
NP.Title="hello"
NP.Body="world"
data := map[string]string{
"msg": "Hello World1",
"sum": "Happy Day",
}
ids := []string{
"token1",
}
xds := []string{
"token5",
"token6",
"token7",
}
c := fcm.NewFcmClient(serverKey)
c.NewFcmRegIdsMsg(ids, data)
c.AppendDevices(xds)
c.SetNotificationPayload(&NP)
status, err := c.Send()
if err == nil {
status.PrintResults()
} else {
fmt.Println(err)`enter code here`
}
}
try this it works cool.
Your question is vague and you could have answered it by simply googling fcm golang or something around the line. Basically here's a list of libraries:
https://golanglibs.com/top?q=firebase
It seems like most of them have some examples + docs. I'd generally speaking go with the most popular:
https://github.com/zabawaba99/firego
Because you can inspire yourself from github issues and the docs are kind of decent:
https://godoc.org/gopkg.in/zabawaba99/firego.v1
Small note, if any go library seems to lack examples/docs try running godocs in the folder or (even faster), try to first look for a GoDocs link on the github page.