From e546eef96c092952206aab10d003fbf607ae377d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 26 Oct 2022 19:20:37 +0300 Subject: [PATCH] client: add ContextDialer/WithContextDialer option Signed-off-by: Vasiliy Tolstov --- client/options.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/options.go b/client/options.go index c7abd912..6416756f 100644 --- a/client/options.go +++ b/client/options.go @@ -3,6 +3,7 @@ package client import ( "context" "crypto/tls" + "net" "time" "go.unistack.org/micro/v3/broker" @@ -56,6 +57,8 @@ type Options struct { PoolSize int // PoolTTL connection pool ttl PoolTTL time.Duration + // ContextDialer used to connect + ContextDialer func(context.Context, string) (net.Conn, error) } // NewCallOptions creates new call options struct @@ -99,6 +102,15 @@ type CallOptions struct { DialTimeout time.Duration // Retries specifies retries num Retries int + // ContextDialer used to connect + ContextDialer func(context.Context, string) (net.Conn, error) +} + +// ContextDialer pass ContextDialer to client +func ContextDialer(fn func(context.Context, string) (net.Conn, error)) Option { + return func(o *Options) { + o.ContextDialer = fn + } } // Context pass context to client @@ -413,6 +425,13 @@ func PublishContext(ctx context.Context) PublishOption { } } +// WithContextDialer pass ContextDialer to client call +func WithContextDialer(fn func(context.Context, string) (net.Conn, error)) CallOption { + return func(o *CallOptions) { + o.ContextDialer = fn + } +} + // WithContentType specifies call content type func WithContentType(ct string) CallOption { return func(o *CallOptions) { -- 2.45.2