Skip to content

Commit

Permalink
Allow overriding default http.Client
Browse files Browse the repository at this point in the history
- Add `teamsClient.SetHTTPClient()` method to allow client code
  to replace default `http.Client` with custom value
- Update `API` interface to expose new `SetHTTPClient()` method
- Light doc updates to reflect this change

refs GH-135
  • Loading branch information
atc0005 committed Feb 8, 2022
1 parent eaab5cd commit 884e59f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -69,6 +69,7 @@ information.
validation behavior
- Configurable timeouts
- Configurable retry support
- Support for overriding the default `http.Client`

## Project Status

Expand Down
2 changes: 2 additions & 0 deletions doc.go
Expand Up @@ -33,6 +33,8 @@ FEATURES
• Configurable retry support
• Support for overriding the default http.Client
USAGE
Expand Down
9 changes: 9 additions & 0 deletions send.go
Expand Up @@ -89,6 +89,7 @@ type API interface {
Send(webhookURL string, webhookMessage MessageCard) error
SendWithContext(ctx context.Context, webhookURL string, webhookMessage MessageCard) error
SendWithRetry(ctx context.Context, webhookURL string, webhookMessage MessageCard, retries int, retriesDelay int) error
SetHTTPClient(httpClient *http.Client) API
SkipWebhookURLValidationOnSend(skip bool) API
AddWebhookURLValidationPatterns(patterns ...string) API
ValidateWebhook(webhookURL string) error
Expand Down Expand Up @@ -133,6 +134,14 @@ func NewClient() API {
return &client
}

// SetHTTPClient accepts a custom http.Client value which replaces the
// existing default http.Client.
func (c *teamsClient) SetHTTPClient(httpClient *http.Client) API {
c.httpClient = httpClient

return c
}

func (c *teamsClient) AddWebhookURLValidationPatterns(patterns ...string) API {
c.webhookURLValidationPatterns = append(c.webhookURLValidationPatterns, patterns...)
return c
Expand Down

0 comments on commit 884e59f

Please sign in to comment.