Firebase Cloud Messaging client in Go. A lightweight alternative to firebase.google.com/go/v4.
firebase.google.com/go/v4 has tremendous dependencies, resulting in nearly 1,000,000 lines of code (as of v4.18.0).
There are many features in the original library, but sending a push notification via FCM requires just a single HTTP request.
That’s exactly what this library provides.
- Simple API.
- Clean and tested code.
- Dependency-free (only golang.org/x/oauth2)
Go version 1.24+
go get github.com/cristalhq/fcm
Build new token:
creds := []byte("...") // your JSON file from Firebase project settings
cfg := fcm.Config{
ProjectID: "example-android-app",
Credentials: creds,
}
client, err := fcm.NewClient(cfg)
if err != nil {
panic(err)
}
deviceToken := "..."
msg := &fcm.Message{
Data: map[string]string{
"force_show": "1",
},
Notification: &fcm.Notification{
Title: "Test",
Body: "Push from https://github.com/cristalhq/fcm",
},
Token: deviceToken,
}
pushID, err := client.Send(ctx, msg)
if err != nil {
panic(err)
}
fmt.Printf("pushID: %s\n", pushID)Also see examples: example_test.go.
See these docs.