client: add ContextDialer/WithContextDialer option #147

Merged
vtolstov merged 1 commits from client_context_dialer into v3 2022-10-26 19:23:01 +03:00

View File

@ -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) {