-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
61 lines (54 loc) · 1.23 KB
/
utils.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
50
51
52
53
54
55
56
57
58
59
60
61
package grpcerrors
import (
"golang.org/x/net/context"
"google.golang.org/grpc"
)
type composedUnaryServerErrorHandler struct {
handlers []UnaryServerErrorHandler
}
func composeUnaryServerErrorHandlers(handlers []UnaryServerErrorHandler) UnaryServerErrorHandler {
return &composedUnaryServerErrorHandler{
handlers: handlers,
}
}
func (ch *composedUnaryServerErrorHandler) HandleUnaryServerError(
c context.Context,
req interface{},
info *grpc.UnaryServerInfo,
err error,
) error {
if err != nil {
for _, h := range ch.handlers {
err = h.HandleUnaryServerError(c, req, info, err)
if err == nil {
break
}
}
}
return err
}
type composedStreamServerErrorHandler struct {
handlers []StreamServerErrorHandler
}
func composeStreamServerErrorHandlers(handlers []StreamServerErrorHandler) StreamServerErrorHandler {
return &composedStreamServerErrorHandler{
handlers: handlers,
}
}
func (ch *composedStreamServerErrorHandler) HandleStreamServerError(
c context.Context,
req interface{},
resp interface{},
info *grpc.StreamServerInfo,
err error,
) error {
if err != nil {
for _, h := range ch.handlers {
err = h.HandleStreamServerError(c, req, resp, info, err)
if err == nil {
break
}
}
}
return err
}