Merge pull request #147 from unistack-org/client_context_dialer

client: add ContextDialer/WithContextDialer option
This commit is contained in:
Василий Толстов 2022-10-26 19:23:01 +03:00 committed by GitHub
commit b2abb86971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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