-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use configuration options for constructing client
- Loading branch information
1 parent
65c7881
commit fae0e83
Showing
5 changed files
with
102 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
*.iml | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package doq | ||
|
||
import ( | ||
"crypto/tls" | ||
"time" | ||
) | ||
|
||
// Option represents configuration options for doq.Client. | ||
type Option interface { | ||
apply(c *Client) | ||
} | ||
|
||
type tlsConfigOption struct { | ||
tlsConfig *tls.Config | ||
} | ||
|
||
func (o *tlsConfigOption) apply(c *Client) { | ||
c.tlsConfig = o.tlsConfig.Clone() | ||
} | ||
|
||
// WithTLSConfig is a configuration option that sets TLS configuration for the doq.Client. | ||
func WithTLSConfig(c *tls.Config) Option { | ||
return &tlsConfigOption{ | ||
tlsConfig: c, | ||
} | ||
} | ||
|
||
type writeTimeoutOption struct { | ||
writeTimeout time.Duration | ||
} | ||
|
||
func (o *writeTimeoutOption) apply(c *Client) { | ||
c.writeTimeout = o.writeTimeout | ||
} | ||
|
||
// WithWriteTimeout is a configuration option that sets write timeout for the doq.Client. | ||
func WithWriteTimeout(t time.Duration) Option { | ||
return &writeTimeoutOption{ | ||
writeTimeout: t, | ||
} | ||
} | ||
|
||
type readTimeoutOption struct { | ||
readTimeout time.Duration | ||
} | ||
|
||
func (o *readTimeoutOption) apply(c *Client) { | ||
c.readTimeout = o.readTimeout | ||
} | ||
|
||
// WithReadTimeout is a configuration option that sets read timeout for the doq.Client. | ||
func WithReadTimeout(t time.Duration) Option { | ||
return &readTimeoutOption{ | ||
readTimeout: t, | ||
} | ||
} | ||
|
||
type connectTimeoutOption struct { | ||
connectTimeout time.Duration | ||
} | ||
|
||
func (o *connectTimeoutOption) apply(c *Client) { | ||
c.connectTimeout = o.connectTimeout | ||
} | ||
|
||
// WithConnectTimeout is a configuration option that sets connect timeout for the doq.Client. | ||
func WithConnectTimeout(t time.Duration) Option { | ||
return &connectTimeoutOption{ | ||
connectTimeout: t, | ||
} | ||
} |