-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelloworld.go
43 lines (35 loc) · 948 Bytes
/
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 validations
import (
"context"
"fmt"
helloworld "github.com/go-masonry/mortar-template/api"
"github.com/go-masonry/mortar/interfaces/auth/jwt"
"github.com/go-masonry/mortar/interfaces/log"
"go.uber.org/fx"
)
type HelloworldValidations interface {
helloworld.GreeterServer
}
type helloworldValidationsDeps struct {
fx.In
jwt.TokenExtractor
Logger log.Logger
}
type helloworldValidationsImpl struct {
*helloworld.UnimplementedGreeterServer
deps helloworldValidationsDeps
}
func CreateHelloworldValidations(deps helloworldValidationsDeps) HelloworldValidations {
return &helloworldValidationsImpl{
deps: deps,
}
}
func (impl *helloworldValidationsImpl) SayHello(ctx context.Context, req *helloworld.HelloRequest) (_ *helloworld.HelloReply, err error) {
if err = impl.CheckAuth(ctx); err != nil {
return nil, err
}
if len(req.GetName()) == 0 {
return nil, fmt.Errorf("name cannot be empty")
}
return nil, nil
}