-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.go
38 lines (29 loc) · 947 Bytes
/
controller.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
package controllers
import (
"context"
helloworld "github.com/go-masonry/mortar-template/api"
"github.com/go-masonry/mortar/interfaces/log"
"go.uber.org/fx"
)
type HelloWorldController interface {
helloworld.GreeterServer
}
type helloworldControllerDeps struct {
fx.In
Logger log.Logger
}
type helloworldControllerImpl struct {
*helloworld.UnimplementedGreeterServer // if keep this one added even when you change your interface this code will compile
deps helloworldControllerDeps
}
func CreateHelloworldController(deps helloworldControllerDeps) HelloWorldController {
return &helloworldControllerImpl{
deps: deps,
}
}
func (w *helloworldControllerImpl) SayHello(ctx context.Context, req *helloworld.HelloRequest) (*helloworld.HelloReply, error) {
w.deps.Logger.Debug(ctx, "saying hello to %s", req.GetName())
return &helloworld.HelloReply{
Message: "Hello " + req.GetName(),
}, nil
}