export WithUnaryClientInterceptor

This commit is contained in:
kevin
2020-10-20 18:03:05 +08:00
parent cee170f3e9
commit 1abe21aa2a
2 changed files with 22 additions and 9 deletions

View File

@@ -11,8 +11,9 @@ import (
) )
var ( var (
WithDialOption = internal.WithDialOption WithDialOption = internal.WithDialOption
WithTimeout = internal.WithTimeout WithTimeout = internal.WithTimeout
WithUnaryClientInterceptor = internal.WithUnaryClientInterceptor
) )
type ( type (

View File

@@ -60,14 +60,26 @@ func TestDepositServer_Deposit(t *testing.T) {
}, },
} }
directClient := MustNewClient(RpcClientConf{ directClient := MustNewClient(
Endpoints: []string{"foo"}, RpcClientConf{
App: "foo", Endpoints: []string{"foo"},
Token: "bar", App: "foo",
Timeout: 1000, Token: "bar",
}, WithDialOption(grpc.WithInsecure()), WithDialOption(grpc.WithContextDialer(dialer()))) Timeout: 1000,
},
WithDialOption(grpc.WithInsecure()),
WithDialOption(grpc.WithContextDialer(dialer())),
WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(ctx, method, req, reply, cc, opts...)
}),
)
targetClient, err := NewClientWithTarget("foo", WithDialOption(grpc.WithInsecure()), targetClient, err := NewClientWithTarget("foo", WithDialOption(grpc.WithInsecure()),
WithDialOption(grpc.WithContextDialer(dialer()))) WithDialOption(grpc.WithContextDialer(dialer())), WithUnaryClientInterceptor(
func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
return invoker(ctx, method, req, reply, cc, opts...)
}))
assert.Nil(t, err) assert.Nil(t, err)
clients := []Client{ clients := []Client{
directClient, directClient,