-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (45 loc) · 1.46 KB
/
main.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
// comment
package main
import (
"context"
v4 "firebase.google.com/go/v4"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"google.golang.org/api/option"
"log"
"net/http"
// your protoPathHere
"github.com/lcmaguire/protoc-gen-go-goo/examplefirebase/sampleconnect"
// your services
"github.com/lcmaguire/protoc-gen-go-goo/examplefirebase/exampleservice"
)
func main() {
mux := http.NewServeMux()
// The generated constructors return a path and a plain net/http
// handler.
// change to be RegisteredServices template
mux.Handle(sampleconnect.NewExampleServiceHandler(createNewService()))
err := http.ListenAndServe(
"localhost:8080", // todo have this not be hardcoded.
// For gRPC clients, it's convenient to support HTTP/2 without TLS. You can
// avoid x/net/http2 by using http.ListenAndServeTLS.
h2c.NewHandler(mux, &http2.Server{}),
)
log.Fatalf("listen failed: " + err.Error())
}
func createNewService() *exampleservice.Service {
opt := option.WithCredentialsFile("your-firebase-service-account.json") // todo have this be env var
app, err := v4.NewApp(context.Background(), nil, opt)
if err != nil {
log.Fatalf("error initializing app: %v\n", err)
}
auth, err := app.Auth(context.Background())
if err != nil {
log.Fatalf("error initializing app: %v\n", err)
}
firestore, err := app.Firestore(context.Background())
if err != nil {
log.Fatalf("error initializing app: %v\n", err)
}
return exampleservice.NewService(auth, firestore)
}