dialoptions.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. *
  3. * Copyright 2018 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. package grpc
  19. import (
  20. "context"
  21. "net"
  22. "time"
  23. "google.golang.org/grpc/backoff"
  24. "google.golang.org/grpc/channelz"
  25. "google.golang.org/grpc/credentials"
  26. "google.golang.org/grpc/credentials/insecure"
  27. "google.golang.org/grpc/internal"
  28. internalbackoff "google.golang.org/grpc/internal/backoff"
  29. "google.golang.org/grpc/internal/transport"
  30. "google.golang.org/grpc/keepalive"
  31. "google.golang.org/grpc/resolver"
  32. "google.golang.org/grpc/stats"
  33. )
  34. func init() {
  35. internal.AddExtraDialOptions = func(opt ...DialOption) {
  36. extraDialOptions = append(extraDialOptions, opt...)
  37. }
  38. internal.ClearExtraDialOptions = func() {
  39. extraDialOptions = nil
  40. }
  41. }
  42. // dialOptions configure a Dial call. dialOptions are set by the DialOption
  43. // values passed to Dial.
  44. type dialOptions struct {
  45. unaryInt UnaryClientInterceptor
  46. streamInt StreamClientInterceptor
  47. chainUnaryInts []UnaryClientInterceptor
  48. chainStreamInts []StreamClientInterceptor
  49. cp Compressor
  50. dc Decompressor
  51. bs internalbackoff.Strategy
  52. block bool
  53. returnLastError bool
  54. timeout time.Duration
  55. scChan <-chan ServiceConfig
  56. authority string
  57. copts transport.ConnectOptions
  58. callOptions []CallOption
  59. channelzParentID *channelz.Identifier
  60. disableServiceConfig bool
  61. disableRetry bool
  62. disableHealthCheck bool
  63. healthCheckFunc internal.HealthChecker
  64. minConnectTimeout func() time.Duration
  65. defaultServiceConfig *ServiceConfig // defaultServiceConfig is parsed from defaultServiceConfigRawJSON.
  66. defaultServiceConfigRawJSON *string
  67. resolvers []resolver.Builder
  68. }
  69. // DialOption configures how we set up the connection.
  70. type DialOption interface {
  71. apply(*dialOptions)
  72. }
  73. var extraDialOptions []DialOption
  74. // EmptyDialOption does not alter the dial configuration. It can be embedded in
  75. // another structure to build custom dial options.
  76. //
  77. // Experimental
  78. //
  79. // Notice: This type is EXPERIMENTAL and may be changed or removed in a
  80. // later release.
  81. type EmptyDialOption struct{}
  82. func (EmptyDialOption) apply(*dialOptions) {}
  83. // funcDialOption wraps a function that modifies dialOptions into an
  84. // implementation of the DialOption interface.
  85. type funcDialOption struct {
  86. f func(*dialOptions)
  87. }
  88. func (fdo *funcDialOption) apply(do *dialOptions) {
  89. fdo.f(do)
  90. }
  91. func newFuncDialOption(f func(*dialOptions)) *funcDialOption {
  92. return &funcDialOption{
  93. f: f,
  94. }
  95. }
  96. // WithWriteBufferSize determines how much data can be batched before doing a
  97. // write on the wire. The corresponding memory allocation for this buffer will
  98. // be twice the size to keep syscalls low. The default value for this buffer is
  99. // 32KB.
  100. //
  101. // Zero will disable the write buffer such that each write will be on underlying
  102. // connection. Note: A Send call may not directly translate to a write.
  103. func WithWriteBufferSize(s int) DialOption {
  104. return newFuncDialOption(func(o *dialOptions) {
  105. o.copts.WriteBufferSize = s
  106. })
  107. }
  108. // WithReadBufferSize lets you set the size of read buffer, this determines how
  109. // much data can be read at most for each read syscall.
  110. //
  111. // The default value for this buffer is 32KB. Zero will disable read buffer for
  112. // a connection so data framer can access the underlying conn directly.
  113. func WithReadBufferSize(s int) DialOption {
  114. return newFuncDialOption(func(o *dialOptions) {
  115. o.copts.ReadBufferSize = s
  116. })
  117. }
  118. // WithInitialWindowSize returns a DialOption which sets the value for initial
  119. // window size on a stream. The lower bound for window size is 64K and any value
  120. // smaller than that will be ignored.
  121. func WithInitialWindowSize(s int32) DialOption {
  122. return newFuncDialOption(func(o *dialOptions) {
  123. o.copts.InitialWindowSize = s
  124. })
  125. }
  126. // WithInitialConnWindowSize returns a DialOption which sets the value for
  127. // initial window size on a connection. The lower bound for window size is 64K
  128. // and any value smaller than that will be ignored.
  129. func WithInitialConnWindowSize(s int32) DialOption {
  130. return newFuncDialOption(func(o *dialOptions) {
  131. o.copts.InitialConnWindowSize = s
  132. })
  133. }
  134. // WithMaxMsgSize returns a DialOption which sets the maximum message size the
  135. // client can receive.
  136. //
  137. // Deprecated: use WithDefaultCallOptions(MaxCallRecvMsgSize(s)) instead. Will
  138. // be supported throughout 1.x.
  139. func WithMaxMsgSize(s int) DialOption {
  140. return WithDefaultCallOptions(MaxCallRecvMsgSize(s))
  141. }
  142. // WithDefaultCallOptions returns a DialOption which sets the default
  143. // CallOptions for calls over the connection.
  144. func WithDefaultCallOptions(cos ...CallOption) DialOption {
  145. return newFuncDialOption(func(o *dialOptions) {
  146. o.callOptions = append(o.callOptions, cos...)
  147. })
  148. }
  149. // WithCodec returns a DialOption which sets a codec for message marshaling and
  150. // unmarshaling.
  151. //
  152. // Deprecated: use WithDefaultCallOptions(ForceCodec(_)) instead. Will be
  153. // supported throughout 1.x.
  154. func WithCodec(c Codec) DialOption {
  155. return WithDefaultCallOptions(CallCustomCodec(c))
  156. }
  157. // WithCompressor returns a DialOption which sets a Compressor to use for
  158. // message compression. It has lower priority than the compressor set by the
  159. // UseCompressor CallOption.
  160. //
  161. // Deprecated: use UseCompressor instead. Will be supported throughout 1.x.
  162. func WithCompressor(cp Compressor) DialOption {
  163. return newFuncDialOption(func(o *dialOptions) {
  164. o.cp = cp
  165. })
  166. }
  167. // WithDecompressor returns a DialOption which sets a Decompressor to use for
  168. // incoming message decompression. If incoming response messages are encoded
  169. // using the decompressor's Type(), it will be used. Otherwise, the message
  170. // encoding will be used to look up the compressor registered via
  171. // encoding.RegisterCompressor, which will then be used to decompress the
  172. // message. If no compressor is registered for the encoding, an Unimplemented
  173. // status error will be returned.
  174. //
  175. // Deprecated: use encoding.RegisterCompressor instead. Will be supported
  176. // throughout 1.x.
  177. func WithDecompressor(dc Decompressor) DialOption {
  178. return newFuncDialOption(func(o *dialOptions) {
  179. o.dc = dc
  180. })
  181. }
  182. // WithServiceConfig returns a DialOption which has a channel to read the
  183. // service configuration.
  184. //
  185. // Deprecated: service config should be received through name resolver or via
  186. // WithDefaultServiceConfig, as specified at
  187. // https://github.com/grpc/grpc/blob/master/doc/service_config.md. Will be
  188. // removed in a future 1.x release.
  189. func WithServiceConfig(c <-chan ServiceConfig) DialOption {
  190. return newFuncDialOption(func(o *dialOptions) {
  191. o.scChan = c
  192. })
  193. }
  194. // WithConnectParams configures the ClientConn to use the provided ConnectParams
  195. // for creating and maintaining connections to servers.
  196. //
  197. // The backoff configuration specified as part of the ConnectParams overrides
  198. // all defaults specified in
  199. // https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md. Consider
  200. // using the backoff.DefaultConfig as a base, in cases where you want to
  201. // override only a subset of the backoff configuration.
  202. func WithConnectParams(p ConnectParams) DialOption {
  203. return newFuncDialOption(func(o *dialOptions) {
  204. o.bs = internalbackoff.Exponential{Config: p.Backoff}
  205. o.minConnectTimeout = func() time.Duration {
  206. return p.MinConnectTimeout
  207. }
  208. })
  209. }
  210. // WithBackoffMaxDelay configures the dialer to use the provided maximum delay
  211. // when backing off after failed connection attempts.
  212. //
  213. // Deprecated: use WithConnectParams instead. Will be supported throughout 1.x.
  214. func WithBackoffMaxDelay(md time.Duration) DialOption {
  215. return WithBackoffConfig(BackoffConfig{MaxDelay: md})
  216. }
  217. // WithBackoffConfig configures the dialer to use the provided backoff
  218. // parameters after connection failures.
  219. //
  220. // Deprecated: use WithConnectParams instead. Will be supported throughout 1.x.
  221. func WithBackoffConfig(b BackoffConfig) DialOption {
  222. bc := backoff.DefaultConfig
  223. bc.MaxDelay = b.MaxDelay
  224. return withBackoff(internalbackoff.Exponential{Config: bc})
  225. }
  226. // withBackoff sets the backoff strategy used for connectRetryNum after a failed
  227. // connection attempt.
  228. //
  229. // This can be exported if arbitrary backoff strategies are allowed by gRPC.
  230. func withBackoff(bs internalbackoff.Strategy) DialOption {
  231. return newFuncDialOption(func(o *dialOptions) {
  232. o.bs = bs
  233. })
  234. }
  235. // WithBlock returns a DialOption which makes callers of Dial block until the
  236. // underlying connection is up. Without this, Dial returns immediately and
  237. // connecting the server happens in background.
  238. func WithBlock() DialOption {
  239. return newFuncDialOption(func(o *dialOptions) {
  240. o.block = true
  241. })
  242. }
  243. // WithReturnConnectionError returns a DialOption which makes the client connection
  244. // return a string containing both the last connection error that occurred and
  245. // the context.DeadlineExceeded error.
  246. // Implies WithBlock()
  247. //
  248. // Experimental
  249. //
  250. // Notice: This API is EXPERIMENTAL and may be changed or removed in a
  251. // later release.
  252. func WithReturnConnectionError() DialOption {
  253. return newFuncDialOption(func(o *dialOptions) {
  254. o.block = true
  255. o.returnLastError = true
  256. })
  257. }
  258. // WithInsecure returns a DialOption which disables transport security for this
  259. // ClientConn. Under the hood, it uses insecure.NewCredentials().
  260. //
  261. // Note that using this DialOption with per-RPC credentials (through
  262. // WithCredentialsBundle or WithPerRPCCredentials) which require transport
  263. // security is incompatible and will cause grpc.Dial() to fail.
  264. //
  265. // Deprecated: use WithTransportCredentials and insecure.NewCredentials()
  266. // instead. Will be supported throughout 1.x.
  267. func WithInsecure() DialOption {
  268. return newFuncDialOption(func(o *dialOptions) {
  269. o.copts.TransportCredentials = insecure.NewCredentials()
  270. })
  271. }
  272. // WithNoProxy returns a DialOption which disables the use of proxies for this
  273. // ClientConn. This is ignored if WithDialer or WithContextDialer are used.
  274. //
  275. // Experimental
  276. //
  277. // Notice: This API is EXPERIMENTAL and may be changed or removed in a
  278. // later release.
  279. func WithNoProxy() DialOption {
  280. return newFuncDialOption(func(o *dialOptions) {
  281. o.copts.UseProxy = false
  282. })
  283. }
  284. // WithTransportCredentials returns a DialOption which configures a connection
  285. // level security credentials (e.g., TLS/SSL). This should not be used together
  286. // with WithCredentialsBundle.
  287. func WithTransportCredentials(creds credentials.TransportCredentials) DialOption {
  288. return newFuncDialOption(func(o *dialOptions) {
  289. o.copts.TransportCredentials = creds
  290. })
  291. }
  292. // WithPerRPCCredentials returns a DialOption which sets credentials and places
  293. // auth state on each outbound RPC.
  294. func WithPerRPCCredentials(creds credentials.PerRPCCredentials) DialOption {
  295. return newFuncDialOption(func(o *dialOptions) {
  296. o.copts.PerRPCCredentials = append(o.copts.PerRPCCredentials, creds)
  297. })
  298. }
  299. // WithCredentialsBundle returns a DialOption to set a credentials bundle for
  300. // the ClientConn.WithCreds. This should not be used together with
  301. // WithTransportCredentials.
  302. //
  303. // Experimental
  304. //
  305. // Notice: This API is EXPERIMENTAL and may be changed or removed in a
  306. // later release.
  307. func WithCredentialsBundle(b credentials.Bundle) DialOption {
  308. return newFuncDialOption(func(o *dialOptions) {
  309. o.copts.CredsBundle = b
  310. })
  311. }
  312. // WithTimeout returns a DialOption that configures a timeout for dialing a
  313. // ClientConn initially. This is valid if and only if WithBlock() is present.
  314. //
  315. // Deprecated: use DialContext instead of Dial and context.WithTimeout
  316. // instead. Will be supported throughout 1.x.
  317. func WithTimeout(d time.Duration) DialOption {
  318. return newFuncDialOption(func(o *dialOptions) {
  319. o.timeout = d
  320. })
  321. }
  322. // WithContextDialer returns a DialOption that sets a dialer to create
  323. // connections. If FailOnNonTempDialError() is set to true, and an error is
  324. // returned by f, gRPC checks the error's Temporary() method to decide if it
  325. // should try to reconnect to the network address.
  326. func WithContextDialer(f func(context.Context, string) (net.Conn, error)) DialOption {
  327. return newFuncDialOption(func(o *dialOptions) {
  328. o.copts.Dialer = f
  329. })
  330. }
  331. func init() {
  332. internal.WithHealthCheckFunc = withHealthCheckFunc
  333. }
  334. // WithDialer returns a DialOption that specifies a function to use for dialing
  335. // network addresses. If FailOnNonTempDialError() is set to true, and an error
  336. // is returned by f, gRPC checks the error's Temporary() method to decide if it
  337. // should try to reconnect to the network address.
  338. //
  339. // Deprecated: use WithContextDialer instead. Will be supported throughout
  340. // 1.x.
  341. func WithDialer(f func(string, time.Duration) (net.Conn, error)) DialOption {
  342. return WithContextDialer(
  343. func(ctx context.Context, addr string) (net.Conn, error) {
  344. if deadline, ok := ctx.Deadline(); ok {
  345. return f(addr, time.Until(deadline))
  346. }
  347. return f(addr, 0)
  348. })
  349. }
  350. // WithStatsHandler returns a DialOption that specifies the stats handler for
  351. // all the RPCs and underlying network connections in this ClientConn.
  352. func WithStatsHandler(h stats.Handler) DialOption {
  353. return newFuncDialOption(func(o *dialOptions) {
  354. o.copts.StatsHandlers = append(o.copts.StatsHandlers, h)
  355. })
  356. }
  357. // FailOnNonTempDialError returns a DialOption that specifies if gRPC fails on
  358. // non-temporary dial errors. If f is true, and dialer returns a non-temporary
  359. // error, gRPC will fail the connection to the network address and won't try to
  360. // reconnect. The default value of FailOnNonTempDialError is false.
  361. //
  362. // FailOnNonTempDialError only affects the initial dial, and does not do
  363. // anything useful unless you are also using WithBlock().
  364. //
  365. // Experimental
  366. //
  367. // Notice: This API is EXPERIMENTAL and may be changed or removed in a
  368. // later release.
  369. func FailOnNonTempDialError(f bool) DialOption {
  370. return newFuncDialOption(func(o *dialOptions) {
  371. o.copts.FailOnNonTempDialError = f
  372. })
  373. }
  374. // WithUserAgent returns a DialOption that specifies a user agent string for all
  375. // the RPCs.
  376. func WithUserAgent(s string) DialOption {
  377. return newFuncDialOption(func(o *dialOptions) {
  378. o.copts.UserAgent = s
  379. })
  380. }
  381. // WithKeepaliveParams returns a DialOption that specifies keepalive parameters
  382. // for the client transport.
  383. func WithKeepaliveParams(kp keepalive.ClientParameters) DialOption {
  384. if kp.Time < internal.KeepaliveMinPingTime {
  385. logger.Warningf("Adjusting keepalive ping interval to minimum period of %v", internal.KeepaliveMinPingTime)
  386. kp.Time = internal.KeepaliveMinPingTime
  387. }
  388. return newFuncDialOption(func(o *dialOptions) {
  389. o.copts.KeepaliveParams = kp
  390. })
  391. }
  392. // WithUnaryInterceptor returns a DialOption that specifies the interceptor for
  393. // unary RPCs.
  394. func WithUnaryInterceptor(f UnaryClientInterceptor) DialOption {
  395. return newFuncDialOption(func(o *dialOptions) {
  396. o.unaryInt = f
  397. })
  398. }
  399. // WithChainUnaryInterceptor returns a DialOption that specifies the chained
  400. // interceptor for unary RPCs. The first interceptor will be the outer most,
  401. // while the last interceptor will be the inner most wrapper around the real call.
  402. // All interceptors added by this method will be chained, and the interceptor
  403. // defined by WithUnaryInterceptor will always be prepended to the chain.
  404. func WithChainUnaryInterceptor(interceptors ...UnaryClientInterceptor) DialOption {
  405. return newFuncDialOption(func(o *dialOptions) {
  406. o.chainUnaryInts = append(o.chainUnaryInts, interceptors...)
  407. })
  408. }
  409. // WithStreamInterceptor returns a DialOption that specifies the interceptor for
  410. // streaming RPCs.
  411. func WithStreamInterceptor(f StreamClientInterceptor) DialOption {
  412. return newFuncDialOption(func(o *dialOptions) {
  413. o.streamInt = f
  414. })
  415. }
  416. // WithChainStreamInterceptor returns a DialOption that specifies the chained
  417. // interceptor for streaming RPCs. The first interceptor will be the outer most,
  418. // while the last interceptor will be the inner most wrapper around the real call.
  419. // All interceptors added by this method will be chained, and the interceptor
  420. // defined by WithStreamInterceptor will always be prepended to the chain.
  421. func WithChainStreamInterceptor(interceptors ...StreamClientInterceptor) DialOption {
  422. return newFuncDialOption(func(o *dialOptions) {
  423. o.chainStreamInts = append(o.chainStreamInts, interceptors...)
  424. })
  425. }
  426. // WithAuthority returns a DialOption that specifies the value to be used as the
  427. // :authority pseudo-header and as the server name in authentication handshake.
  428. func WithAuthority(a string) DialOption {
  429. return newFuncDialOption(func(o *dialOptions) {
  430. o.authority = a
  431. })
  432. }
  433. // WithChannelzParentID returns a DialOption that specifies the channelz ID of
  434. // current ClientConn's parent. This function is used in nested channel creation
  435. // (e.g. grpclb dial).
  436. //
  437. // Experimental
  438. //
  439. // Notice: This API is EXPERIMENTAL and may be changed or removed in a
  440. // later release.
  441. func WithChannelzParentID(id *channelz.Identifier) DialOption {
  442. return newFuncDialOption(func(o *dialOptions) {
  443. o.channelzParentID = id
  444. })
  445. }
  446. // WithDisableServiceConfig returns a DialOption that causes gRPC to ignore any
  447. // service config provided by the resolver and provides a hint to the resolver
  448. // to not fetch service configs.
  449. //
  450. // Note that this dial option only disables service config from resolver. If
  451. // default service config is provided, gRPC will use the default service config.
  452. func WithDisableServiceConfig() DialOption {
  453. return newFuncDialOption(func(o *dialOptions) {
  454. o.disableServiceConfig = true
  455. })
  456. }
  457. // WithDefaultServiceConfig returns a DialOption that configures the default
  458. // service config, which will be used in cases where:
  459. //
  460. // 1. WithDisableServiceConfig is also used, or
  461. //
  462. // 2. The name resolver does not provide a service config or provides an
  463. // invalid service config.
  464. //
  465. // The parameter s is the JSON representation of the default service config.
  466. // For more information about service configs, see:
  467. // https://github.com/grpc/grpc/blob/master/doc/service_config.md
  468. // For a simple example of usage, see:
  469. // examples/features/load_balancing/client/main.go
  470. func WithDefaultServiceConfig(s string) DialOption {
  471. return newFuncDialOption(func(o *dialOptions) {
  472. o.defaultServiceConfigRawJSON = &s
  473. })
  474. }
  475. // WithDisableRetry returns a DialOption that disables retries, even if the
  476. // service config enables them. This does not impact transparent retries, which
  477. // will happen automatically if no data is written to the wire or if the RPC is
  478. // unprocessed by the remote server.
  479. //
  480. // Retry support is currently enabled by default, but may be disabled by
  481. // setting the environment variable "GRPC_GO_RETRY" to "off".
  482. func WithDisableRetry() DialOption {
  483. return newFuncDialOption(func(o *dialOptions) {
  484. o.disableRetry = true
  485. })
  486. }
  487. // WithMaxHeaderListSize returns a DialOption that specifies the maximum
  488. // (uncompressed) size of header list that the client is prepared to accept.
  489. func WithMaxHeaderListSize(s uint32) DialOption {
  490. return newFuncDialOption(func(o *dialOptions) {
  491. o.copts.MaxHeaderListSize = &s
  492. })
  493. }
  494. // WithDisableHealthCheck disables the LB channel health checking for all
  495. // SubConns of this ClientConn.
  496. //
  497. // Experimental
  498. //
  499. // Notice: This API is EXPERIMENTAL and may be changed or removed in a
  500. // later release.
  501. func WithDisableHealthCheck() DialOption {
  502. return newFuncDialOption(func(o *dialOptions) {
  503. o.disableHealthCheck = true
  504. })
  505. }
  506. // withHealthCheckFunc replaces the default health check function with the
  507. // provided one. It makes tests easier to change the health check function.
  508. //
  509. // For testing purpose only.
  510. func withHealthCheckFunc(f internal.HealthChecker) DialOption {
  511. return newFuncDialOption(func(o *dialOptions) {
  512. o.healthCheckFunc = f
  513. })
  514. }
  515. func defaultDialOptions() dialOptions {
  516. return dialOptions{
  517. healthCheckFunc: internal.HealthCheckFunc,
  518. copts: transport.ConnectOptions{
  519. WriteBufferSize: defaultWriteBufSize,
  520. ReadBufferSize: defaultReadBufSize,
  521. UseProxy: true,
  522. },
  523. }
  524. }
  525. // withGetMinConnectDeadline specifies the function that clientconn uses to
  526. // get minConnectDeadline. This can be used to make connection attempts happen
  527. // faster/slower.
  528. //
  529. // For testing purpose only.
  530. func withMinConnectDeadline(f func() time.Duration) DialOption {
  531. return newFuncDialOption(func(o *dialOptions) {
  532. o.minConnectTimeout = f
  533. })
  534. }
  535. // WithResolvers allows a list of resolver implementations to be registered
  536. // locally with the ClientConn without needing to be globally registered via
  537. // resolver.Register. They will be matched against the scheme used for the
  538. // current Dial only, and will take precedence over the global registry.
  539. //
  540. // Experimental
  541. //
  542. // Notice: This API is EXPERIMENTAL and may be changed or removed in a
  543. // later release.
  544. func WithResolvers(rs ...resolver.Builder) DialOption {
  545. return newFuncDialOption(func(o *dialOptions) {
  546. o.resolvers = append(o.resolvers, rs...)
  547. })
  548. }