-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_option.go
More file actions
56 lines (45 loc) · 1.63 KB
/
client_option.go
File metadata and controls
56 lines (45 loc) · 1.63 KB
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
package srpc
import (
_ "github.com/opensraph/srpc/encoding/protobinary" // register protobuf codec
_ "github.com/opensraph/srpc/encoding/protojson" // register json codec
"google.golang.org/grpc"
)
type ClientOption func(o *clientOptions)
type DialOption = grpc.DialOption
type clientOptions struct {
grpcOpts []DialOption
interceptor Interceptor
}
var defaultClientOptions = clientOptions{
grpcOpts: make([]DialOption, 0),
interceptor: Interceptor{
chainUnaryClientInts: make([]UnaryClientInterceptor, 0),
chainStreamClientInts: make([]StreamClientInterceptor, 0),
},
}
var globalClientOptions []ClientOption = []ClientOption{}
func WithGRPCOptions(opts ...DialOption) ClientOption {
return func(o *clientOptions) {
o.grpcOpts = append(o.grpcOpts, opts...)
}
}
func WithUnaryInterceptor(interceptor UnaryClientInterceptor) ClientOption {
return func(o *clientOptions) {
o.interceptor.chainUnaryClientInts = append(o.interceptor.chainUnaryClientInts, interceptor)
}
}
func WithChainUnaryInterceptor(Interceptors ...UnaryClientInterceptor) ClientOption {
return func(o *clientOptions) {
o.interceptor.chainUnaryClientInts = append(o.interceptor.chainUnaryClientInts, Interceptors...)
}
}
func WithStreamInterceptor(interceptor StreamClientInterceptor) ClientOption {
return func(o *clientOptions) {
o.interceptor.chainStreamClientInts = append(o.interceptor.chainStreamClientInts, interceptor)
}
}
func WithChainStreamInterceptor(Interceptors ...StreamClientInterceptor) ClientOption {
return func(o *clientOptions) {
o.interceptor.chainStreamClientInts = append(o.interceptor.chainStreamClientInts, Interceptors...)
}
}