Package list golang-github-go-kit-kit / 01974e5
panic on codec error is better as it's a coding error Bas van Beek 4 years ago
1 changed file(s) with 4 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
11
22 import (
33 "context"
4 "errors"
54
65 pb "github.com/go-kit/kit/transport/grpc/_pb"
76 )
87
98 func encodeRequest(ctx context.Context, req interface{}) (interface{}, error) {
10 r, ok := req.(TestRequest)
11 if !ok {
12 return nil, errors.New("request encode error")
13 }
9 r := req.(TestRequest)
1410 return &pb.TestRequest{A: r.A, B: r.B}, nil
1511 }
1612
1713 func decodeRequest(ctx context.Context, req interface{}) (interface{}, error) {
18 r, ok := req.(*pb.TestRequest)
19 if !ok {
20 return nil, errors.New("request decode error")
21 }
14 r := req.(*pb.TestRequest)
2215 return TestRequest{A: r.A, B: r.B}, nil
2316 }
2417
2518 func encodeResponse(ctx context.Context, resp interface{}) (interface{}, error) {
26 r, ok := resp.(*TestResponse)
27 if !ok {
28 return nil, errors.New("response encode error")
29 }
19 r := resp.(*TestResponse)
3020 return &pb.TestResponse{V: r.V}, nil
3121 }
3222
3323 func decodeResponse(ctx context.Context, resp interface{}) (interface{}, error) {
34 r, ok := resp.(*pb.TestResponse)
35 if !ok {
36 return nil, errors.New("response decode error")
37 }
24 r := resp.(*pb.TestResponse)
3825 return &TestResponse{V: r.V, Ctx: ctx}, nil
3926 }