-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Firebase.go
68 lines (55 loc) · 1.62 KB
/
Firebase.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package wfb
import (
"context"
"fmt"
"os"
"path"
"sync"
firebase "firebase.google.com/go"
// "firebase.google.com/go/auth"
"firebase.google.com/go/messaging"
"google.golang.org/api/option"
"github.com/wasabee-project/Wasabee-Server/config"
"github.com/wasabee-project/Wasabee-Server/log"
wm "github.com/wasabee-project/Wasabee-Server/messaging"
)
var msg *messaging.Client
var fbctx context.Context
var multicastFantoutMutex sync.Mutex
// Start is the main startup function for the Firebase subsystem
func Start(ctx context.Context) {
c := config.Get()
keypath := path.Join(c.Certs, c.FirebaseKey)
if _, err := os.Stat(keypath); err != nil {
log.Debugw("firebase key does not exist, not starting", "key", keypath)
return
}
log.Infow("startup", "subsystem", "Firebase", "version", firebase.Version, "message", "Firebase starting", "key", keypath)
app, err := firebase.NewApp(ctx, nil, option.WithCredentialsFile(keypath))
if err != nil {
err := fmt.Errorf("error initializing firebase messaging: %v", err)
log.Error(err)
return
}
msg, err = app.Messaging(ctx)
if err != nil {
log.Error(err)
return
}
wm.RegisterMessageBus("firebase", wm.Bus{
SendMessage: sendMessage,
SendTarget: sendTarget,
SendAnnounce: sendAnnounce,
AddToRemote: addToRemote,
RemoveFromRemote: removeFromRemote,
// SendAssignment: sendAssignment,
AgentDeleteOperation: agentDeleteOperation,
DeleteOperation: deleteOperation,
})
fbctx = ctx
ratelimitinit()
config.SetFirebaseRunning(true)
<-ctx.Done()
log.Infow("Shutdown", "message", "Firebase Shutting down")
config.SetFirebaseRunning(false)
}