Skip to content

cristalhq/fcm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

fcm

build-img pkg-img reportcard-img coverage-img version-img

Firebase Cloud Messaging client in Go. A lightweight alternative to firebase.google.com/go/v4.

Rationale

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.

Features

Install

Go version 1.24+

go get github.com/cristalhq/fcm

Example

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.

Documentation

See these docs.

License

MIT License.

About

Firebase Cloud Messaging client in Go

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages