-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoption.go
33 lines (28 loc) · 1.08 KB
/
option.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
package app
import (
"google.golang.org/grpc"
)
// Option configures the environment run by Run().
type Option func(o *opts)
type opts struct {
unaryServerInterceptors []grpc.UnaryServerInterceptor
streamServerInterceptors []grpc.StreamServerInterceptor
}
// WithUnaryServerInterceptor configures the app's gRPC server to use the provided interceptor.
//
// Interceptors are evaluated in addition order, and configured interceptors are executed after
// the app's default interceptors.
func WithUnaryServerInterceptor(interceptor grpc.UnaryServerInterceptor) Option {
return func(o *opts) {
o.unaryServerInterceptors = append(o.unaryServerInterceptors, interceptor)
}
}
// WithStreamServerInterceptor configures the app's gRPC server to use the provided interceptor.
//
// Interceptors are evaluated in addition order, and configured interceptors are executed after
// the app's default interceptors.
func WithStreamServerInterceptor(interceptor grpc.StreamServerInterceptor) Option {
return func(o *opts) {
o.streamServerInterceptors = append(o.streamServerInterceptors, interceptor)
}
}