Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transport): add grpc client stream interceptor opts #2610

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions transport/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ func WithUnaryInterceptor(in ...grpc.UnaryClientInterceptor) ClientOption {
}
}

// WithStreamInterceptor returns a DialOption that specifies the interceptor for streaming RPCs.
func WithStreamInterceptor(in ...grpc.StreamClientInterceptor) ClientOption {
return func(o *clientOptions) {
o.streamInts = in
}
}

// WithOptions with gRPC options.
func WithOptions(opts ...grpc.DialOption) ClientOption {
return func(o *clientOptions) {
Expand Down Expand Up @@ -102,6 +109,7 @@ type clientOptions struct {
discovery registry.Discovery
middleware []middleware.Middleware
ints []grpc.UnaryClientInterceptor
streamInts []grpc.StreamClientInterceptor
grpcOpts []grpc.DialOption
balancerName string
filters []selector.NodeFilter
Expand Down Expand Up @@ -135,6 +143,9 @@ func dial(ctx context.Context, insecure bool, opts ...ClientOption) (*grpc.Clien
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"loadBalancingConfig": [{"%s":{}}]}`, options.balancerName)),
grpc.WithChainUnaryInterceptor(ints...),
}
if len(options.streamInts) > 0 {
grpcOpts = append(grpcOpts, grpc.WithChainStreamInterceptor(options.streamInts...))
}
if options.discovery != nil {
grpcOpts = append(grpcOpts,
grpc.WithResolvers(
Expand Down