Documentation ¶
Overview ¶
Package fcm provides message notification integration for Firebase Cloud Messaging (FCM).
Usage:
package main import ( "context" "log" "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/fcm" ) func main() { fcmSvc, err := fcm.New("server_api_key") if err != nil { log.Fatalf("fcm.New() failed: %s", err.Error()) } fcmSvc.AddReceivers("deviceToken1") notifier := notify.New() notifier.UseServices(fcmSvc) // Use context.Background() if you want to send a simple notification message. ctx := context.Background() // Optionally, you can include additional data in the message payload by adding the corresponding value to the context. ctxWithData := context.WithValue(ctx, fcm.DataKey, map[string]interface{}{ "some-key": "some-value", "other-key": "other-value", }) // Optionally, you can specify a total of retry attempts per each message by adding the corresponding value to the context. ctxWithDataAndRetries := context.WithValue(ctxWithData, fcm.RetriesKey, 3) err = notifier.Send(ctxWithDataAndRetries, "subject", "message") if err != nil { log.Fatalf("notifier.Send() failed: %s", err.Error()) } log.Println("notification sent") }
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DataKey is used as a context.Context key to optionally add data to the message payload. DataKey = msgDataKey{} // RetriesKey is used as a context.Context key to optionally set a total of retry attempts per each message. RetriesKey = msgRetriesKey{} )
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service encapsulates the FCM client along with internal state for storing device tokens.
func (*Service) AddReceivers ¶
AddReceivers takes FCM device tokens and appends them to the internal device tokens slice. The Send method will send a given message to all those devices.
Click to show internal directories.
Click to hide internal directories.