veer
veer

Reputation: 83

how to send fcm push notification using golang fcm server

I'm doing Ionic apps, using Cordova fcm plugin I get the device token. Now I want to send the push notification from go server. How to use go as the fcm server? I need some implementation example.

Upvotes: 6

Views: 8688

Answers (2)

solomon abel
solomon abel

Reputation: 166

    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.

Upvotes: 5

George
George

Reputation: 3991

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.

Upvotes: 3

Related Questions