-
Notifications
You must be signed in to change notification settings - Fork 506
/
Copy pathmain.go
44 lines (38 loc) · 1.06 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
package main
import (
"context"
"fmt"
"net/http"
"os"
"strings"
"cloud.google.com/go/firestore"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/genproto/users"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/logs"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/server"
"github.com/go-chi/chi/v5"
"google.golang.org/grpc"
)
func main() {
logs.Init()
ctx := context.Background()
firestoreClient, err := firestore.NewClient(ctx, os.Getenv("GCP_PROJECT"))
if err != nil {
panic(err)
}
firebaseDB := db{firestoreClient}
serverType := strings.ToLower(os.Getenv("SERVER_TO_RUN"))
switch serverType {
case "http":
go loadFixtures()
server.RunHTTPServer(func(router chi.Router) http.Handler {
return HandlerFromMux(HttpServer{firebaseDB}, router)
})
case "grpc":
server.RunGRPCServer(func(server *grpc.Server) {
svc := GrpcServer{firebaseDB}
users.RegisterUsersServiceServer(server, svc)
})
default:
panic(fmt.Sprintf("server type '%s' is not supported", serverType))
}
}