generated from go-masonry/mortar-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helloworld.go
66 lines (57 loc) · 2.1 KB
/
helloworld.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
package mortar
import (
"context"
helloworld "github.com/go-masonry/mortar-template/api"
"github.com/go-masonry/mortar-template/app/controllers"
"github.com/go-masonry/mortar-template/app/services"
"github.com/go-masonry/mortar-template/app/validations"
serverInt "github.com/go-masonry/mortar/interfaces/http/server"
"github.com/go-masonry/mortar/providers/groups"
"google.golang.org/grpc/credentials/insecure"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"go.uber.org/fx"
"google.golang.org/grpc"
)
type workshopServiceDeps struct {
fx.In
// API Implementations, "Register" them as GRPCServiceAPI
Helloworld helloworld.GreeterServer
}
func ServiceAPIsAndOtherDependenciesFxOption() fx.Option {
return fx.Options(
// GRPC Service APIs registration
fx.Provide(fx.Annotated{
Group: groups.GRPCServerAPIs,
Target: serviceGRPCServiceAPIs,
}),
// GRPC Gateway Generated Handlers registration
fx.Provide(fx.Annotated{
Group: groups.GRPCGatewayGeneratedHandlers + ",flatten", // "flatten" does this [][]serverInt.GRPCGatewayGeneratedHandlers -> []serverInt.GRPCGatewayGeneratedHandlers
Target: serviceGRPCGatewayHandlers,
}),
// All other tutorial dependencies
serviceDependencies(),
)
}
func serviceGRPCServiceAPIs(deps workshopServiceDeps) serverInt.GRPCServerAPI {
return func(srv *grpc.Server) {
helloworld.RegisterGreeterServer(srv, deps.Helloworld)
// Any additional gRPC Implementations should be called here
}
}
func serviceGRPCGatewayHandlers() []serverInt.GRPCGatewayGeneratedHandlers {
return []serverInt.GRPCGatewayGeneratedHandlers{
// Register service REST API
func(mux *runtime.ServeMux, localhostEndpoint string) error {
return helloworld.RegisterGreeterHandlerFromEndpoint(context.Background(), mux, localhostEndpoint, []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())})
},
// Any additional gRPC gateway registrations should be called here
}
}
func serviceDependencies() fx.Option {
return fx.Provide(
services.CreateHelloworldService,
controllers.CreateHelloworldController,
validations.CreateHelloworldValidations,
)
}