This repository was archived by the owner on Aug 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtutorial.go
75 lines (67 loc) · 2.53 KB
/
tutorial.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
69
70
71
72
73
74
75
package mortar
import (
"context"
serverInt "github.com/go-masonry/mortar/interfaces/http/server"
"github.com/go-masonry/mortar/providers/groups"
workshop "github.com/go-masonry/tutorial/04-instrumentation/api"
"github.com/go-masonry/tutorial/04-instrumentation/app/controllers"
"github.com/go-masonry/tutorial/04-instrumentation/app/data"
"github.com/go-masonry/tutorial/04-instrumentation/app/services"
"github.com/go-masonry/tutorial/04-instrumentation/app/validations"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"go.uber.org/fx"
"google.golang.org/grpc"
)
type tutorialServiceDeps struct {
fx.In
// API Implementations
Workshop workshop.WorkshopServer
SubWorkshop workshop.SubWorkshopServer
}
func TutorialAPIsAndOtherDependenciesFxOption() fx.Option {
return fx.Options(
// GRPC Service APIs registration
fx.Provide(fx.Annotated{
Group: groups.GRPCServerAPIs,
Target: tutorialGRPCServiceAPIs,
}),
// GRPC Gateway Generated Handlers registration
fx.Provide(fx.Annotated{
Group: groups.GRPCGatewayGeneratedHandlers + ",flatten", // "flatten" does this [][]serverInt.GRPCGatewayGeneratedHandlers -> []serverInt.GRPCGatewayGeneratedHandlers
Target: tutorialGRPCGatewayHandlers,
}),
// All other tutorial dependencies
tutorialDependencies(),
)
}
func tutorialGRPCServiceAPIs(deps tutorialServiceDeps) serverInt.GRPCServerAPI {
return func(srv *grpc.Server) {
workshop.RegisterWorkshopServer(srv, deps.Workshop)
workshop.RegisterSubWorkshopServer(srv, deps.SubWorkshop)
// Any additional gRPC Implementations should be called here
}
}
func tutorialGRPCGatewayHandlers() []serverInt.GRPCGatewayGeneratedHandlers {
return []serverInt.GRPCGatewayGeneratedHandlers{
// Register workshop REST API
func(mux *runtime.ServeMux, endpoint string) error {
return workshop.RegisterWorkshopHandlerFromEndpoint(context.Background(), mux, endpoint, []grpc.DialOption{grpc.WithInsecure()})
},
// Register sub workshop REST API
func(mux *runtime.ServeMux, endpoint string) error {
return workshop.RegisterSubWorkshopHandlerFromEndpoint(context.Background(), mux, endpoint, []grpc.DialOption{grpc.WithInsecure()})
},
// Any additional gRPC gateway registrations should be called here
}
}
func tutorialDependencies() fx.Option {
return fx.Provide(
services.CreateWorkshopService,
services.CreateSubWorkshopService,
controllers.CreateWorkshopController,
controllers.CreateSubWorkshopController,
data.CreateCarDB,
validations.CreateWorkshopValidations,
validations.CreateSubWorkshopValidations,
)
}