-
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 Options pattern for creating Client instance
- Loading branch information
ondrej.benkovsky
committed
Oct 27, 2024
1 parent
5df5b91
commit bcfa858
Showing
4 changed files
with
49 additions
and
31 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
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,23 @@ | ||
package doh | ||
|
||
import "net/http" | ||
|
||
// Option represents configuration options for doh.Client. | ||
type Option interface { | ||
apply(c *Client) | ||
} | ||
|
||
type httpClientOption struct { | ||
client *http.Client | ||
} | ||
|
||
func (o *httpClientOption) apply(c *Client) { | ||
c.client = o.client | ||
} | ||
|
||
// WithHTTPClient is a configuration option that overrides default http.Client instance used by the doh.Client. | ||
func WithHTTPClient(c *http.Client) Option { | ||
return &httpClientOption{ | ||
client: c, | ||
} | ||
} |