Skip to content

Instantly share code, notes, and snippets.

@yaegaki
Last active June 4, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaegaki/290222c60f17827718fd642df7a757b2 to your computer and use it in GitHub Desktop.
Save yaegaki/290222c60f17827718fd642df7a757b2 to your computer and use it in GitHub Desktop.
notification sample
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)
}
cli, err := app.Messaging(ctx)
if err != nil {
log.Fatal(err)
}
msg := &messaging.Message{
Topic: "plan-test",
Notification: &messaging.Notification{
Title: "test",
Body: "test",
},
Data: map[string]string{
"date": "2020-6-4",
},
APNS: &messaging.APNSConfig{
Payload: &messaging.APNSPayload{
Aps: &messaging.Aps{
Sound: "default",
},
},
},
}
s, err := cli.Send(ctx, msg)
if err != nil {
log.Fatal(err)
}
log.Printf("result: %v", s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment