-
Notifications
You must be signed in to change notification settings - Fork 245
/
interceptor.go
52 lines (42 loc) · 1.75 KB
/
interceptor.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
package shared
import (
"google.golang.org/grpc"
"github.com/authzed/spicedb/internal/middleware/servicespecific"
)
// WithUnaryServiceSpecificInterceptor is a helper to add a unary interceptor or interceptor
// chain to a service.
type WithUnaryServiceSpecificInterceptor struct {
Unary grpc.UnaryServerInterceptor
}
// UnaryInterceptor implements servicespecific.ExtraUnaryInterceptor
func (wussi WithUnaryServiceSpecificInterceptor) UnaryInterceptor() grpc.UnaryServerInterceptor {
return wussi.Unary
}
// WithStreamServiceSpecificInterceptor is a helper to add a stream interceptor or interceptor
// chain to a service.
type WithStreamServiceSpecificInterceptor struct {
Stream grpc.StreamServerInterceptor
}
// StreamInterceptor implements servicespecific.ExtraStreamInterceptor
func (wsssi WithStreamServiceSpecificInterceptor) StreamInterceptor() grpc.StreamServerInterceptor {
return wsssi.Stream
}
// WithServiceSpecificInterceptors is a helper to add both a unary and stream interceptor
// or interceptor chain to a service.
type WithServiceSpecificInterceptors struct {
Unary grpc.UnaryServerInterceptor
Stream grpc.StreamServerInterceptor
}
// UnaryInterceptor implements servicespecific.ExtraUnaryInterceptor
func (wssi WithServiceSpecificInterceptors) UnaryInterceptor() grpc.UnaryServerInterceptor {
return wssi.Unary
}
// StreamInterceptor implements servicespecific.ExtraStreamInterceptor
func (wssi WithServiceSpecificInterceptors) StreamInterceptor() grpc.StreamServerInterceptor {
return wssi.Stream
}
var (
_ servicespecific.ExtraUnaryInterceptor = WithUnaryServiceSpecificInterceptor{}
_ servicespecific.ExtraUnaryInterceptor = WithServiceSpecificInterceptors{}
_ servicespecific.ExtraStreamInterceptor = WithServiceSpecificInterceptors{}
)