-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
35 lines (31 loc) · 984 Bytes
/
app.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
// Package firebase provides wrapper functions for Firebase App initialisers.
package firebase
import (
"context"
"fmt"
firebase "firebase.google.com/go"
"google.golang.org/api/option"
)
type FirebaseApp struct {
app *firebase.App
}
// NewApp creates a Firebase app with given configuration.
// If the Config Credentials field is non-empty, the field is used as the credentials file path.
// Otherwise, Google application default credentials are used.
func NewApp(cfg Config) (*FirebaseApp, error) {
var app *firebase.App
var err error
if cfg.Credentials != "" {
opt := option.WithCredentialsFile(cfg.Credentials)
app, err = firebase.NewApp(context.Background(), nil, opt)
if err != nil {
return nil, fmt.Errorf("error initializing app with credentials file: %v", err)
}
} else {
app, err = firebase.NewApp(context.Background(), nil)
if err != nil {
return nil, fmt.Errorf("error initializing app: %v", err)
}
}
return &FirebaseApp{app: app}, nil
}