-
Notifications
You must be signed in to change notification settings - Fork 13
/
fcm.go
28 lines (23 loc) · 1.06 KB
/
fcm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package fcm
import (
"context"
firebase "firebase.google.com/go"
"firebase.google.com/go/messaging"
)
type FCM interface {
Send(ctx context.Context, message *messaging.Message) (string, error)
SendDryRun(ctx context.Context, message *messaging.Message) (string, error)
SendAll(ctx context.Context, messages []*messaging.Message) (*messaging.BatchResponse, error)
SendAllDryRun(ctx context.Context, messages []*messaging.Message) (*messaging.BatchResponse, error)
SendMulticast(ctx context.Context, message *messaging.MulticastMessage) (*messaging.BatchResponse, error)
SendMulticastDryRun(ctx context.Context, message *messaging.MulticastMessage) (*messaging.BatchResponse, error)
SubscribeToTopic(ctx context.Context, tokens []string, topic string) (*messaging.TopicManagementResponse, error)
UnsubscribeFromTopic(ctx context.Context, tokens []string, topic string) (*messaging.TopicManagementResponse, error)
}
func NewFCM(ctx context.Context) (FCM, error) {
app, err := firebase.NewApp(ctx, nil)
if err != nil {
return nil, err
}
return app.Messaging(ctx)
}