-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathendpoint.go
49 lines (40 loc) · 1.21 KB
/
endpoint.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
// Code generated by kun; DO NOT EDIT.
// github.com/RussellLuo/kun
package helloworldgrpc
import (
"context"
"github.com/RussellLuo/kun/pkg/httpoption"
"github.com/RussellLuo/validating/v3"
"github.com/go-kit/kit/endpoint"
)
type SayHelloRequest struct {
Name string `json:"name"`
}
// ValidateSayHelloRequest creates a validator for SayHelloRequest.
func ValidateSayHelloRequest(newSchema func(*SayHelloRequest) validating.Schema) httpoption.Validator {
return httpoption.FuncValidator(func(value interface{}) error {
req := value.(*SayHelloRequest)
return httpoption.Validate(newSchema(req))
})
}
type SayHelloResponse struct {
Message string `json:"message"`
Err error `json:"-"`
}
func (r *SayHelloResponse) Body() interface{} { return r }
// Failed implements endpoint.Failer.
func (r *SayHelloResponse) Failed() error { return r.Err }
// MakeEndpointOfSayHello creates the endpoint for s.SayHello.
func MakeEndpointOfSayHello(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(*SayHelloRequest)
message, err := s.SayHello(
ctx,
req.Name,
)
return &SayHelloResponse{
Message: message,
Err: err,
}, nil
}
}