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 ( import (
"context" "context"
"crypto/tls" "crypto/tls"
"net"
"time" "time"
"go.unistack.org/micro/v3/broker" "go.unistack.org/micro/v3/broker"
@ -56,6 +57,8 @@ type Options struct {
PoolSize int PoolSize int
// PoolTTL connection pool ttl // PoolTTL connection pool ttl
PoolTTL time.Duration PoolTTL time.Duration
// ContextDialer used to connect
ContextDialer func(context.Context, string) (net.Conn, error)
} }
// NewCallOptions creates new call options struct // NewCallOptions creates new call options struct
@ -99,6 +102,15 @@ type CallOptions struct {
DialTimeout time.Duration DialTimeout time.Duration
// Retries specifies retries num // Retries specifies retries num
Retries int 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 // 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 // WithContentType specifies call content type
func WithContentType(ct string) CallOption { func WithContentType(ct string) CallOption {
return func(o *CallOptions) { return func(o *CallOptions) {