client: add ContextDialer/WithContextDialer option

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2022-10-26 19:20:37 +03:00
parent 817bf1f4d0
commit e546eef96c

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