-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
45 lines (38 loc) · 1.14 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
package main
import (
"context"
"fmt"
"net/http"
"os"
"strings"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/genproto/trainer"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/logs"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/common/server"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/ports"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/service"
"github.com/go-chi/chi/v5"
"google.golang.org/grpc"
)
func main() {
logs.Init()
ctx := context.Background()
application := service.NewApplication(ctx)
serverType := strings.ToLower(os.Getenv("SERVER_TO_RUN"))
switch serverType {
case "http":
go loadFixtures(application)
server.RunHTTPServer(func(router chi.Router) http.Handler {
return ports.HandlerFromMux(
ports.NewHttpServer(application),
router,
)
})
case "grpc":
server.RunGRPCServer(func(server *grpc.Server) {
svc := ports.NewGrpcServer(application)
trainer.RegisterTrainerServiceServer(server, svc)
})
default:
panic(fmt.Sprintf("server type '%s' is not supported", serverType))
}
}