Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Last active March 17, 2022 09:43
Show Gist options
  • Save hiranya911/8bac5d089b760988c9562ff2327ceade to your computer and use it in GitHub Desktop.
Save hiranya911/8bac5d089b760988c9562ff2327ceade to your computer and use it in GitHub Desktop.
package main
import (
"context"
"log"
firebase "firebase.google.com/go"
"firebase.google.com/go/messaging"
)
func main() {
ctx := context.Background()
app, err := firebase.NewApp(ctx, nil)
if err != nil {
log.Fatal(err)
}
db, err := app.Firestore(ctx)
if err != nil {
log.Fatal(err)
}
snapshot, err := db.Collection("users").Doc("alice").Get(ctx)
if err != nil {
log.Fatal(err)
}
topic, err := snapshot.DataAt("topicName")
if err != nil {
log.Fatal(err)
}
fcm, err := app.Messaging(ctx)
if err != nil {
log.Fatal(err)
}
resp, err := fcm.Send(ctx, &messaging.Message{
Topic: topic.(string),
Notification: &messaging.Notification{
Title: "Hello from the other side",
Body: "I must have called this proxy a thousand times",
},
})
if err != nil {
log.Fatal(err)
}
log.Println(resp)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment