-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelloworld.go
43 lines (34 loc) · 1.2 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
package services
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/validations"
"github.com/go-masonry/mortar/interfaces/monitor"
"github.com/go-masonry/mortar/interfaces/log"
"go.uber.org/fx"
)
type helloworldServiceDeps struct {
fx.In
Logger log.Logger
Validations validations.HelloworldValidations
Controller controllers.HelloWorldController
Metrics monitor.Metrics `optional:"true"`
}
type helloworldServiceImpl struct {
helloworld.UnimplementedGreeterServer // if keep this one added even when you change your interface this code will compile
deps helloworldServiceDeps
}
func CreateHelloworldService(deps helloworldServiceDeps) helloworld.GreeterServer {
return &helloworldServiceImpl{
deps: deps,
}
}
func (impl *helloworldServiceImpl) SayHello(ctx context.Context, req *helloworld.HelloRequest) (*helloworld.HelloReply, error) {
_, err := impl.deps.Validations.SayHello(ctx, req)
if err != nil {
impl.deps.Logger.WithError(err).Debug(ctx, "validation failed")
return nil, err
}
return impl.deps.Controller.SayHello(ctx, req)
}