Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert recent API changes #151

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ A package to send messages to Microsoft Teams (channels)
- [How to create a webhook URL (Connector)](#how-to-create-a-webhook-url-connector)
- [Examples](#examples)
- [Basic](#basic)
- [Set custom user agent](#set-custom-user-agent)
- [Add an Action](#add-an-action)
- [Disable webhook URL prefix validation](#disable-webhook-url-prefix-validation)
- [Enable custom patterns' validation](#enable-custom-patterns-validation)
Expand Down Expand Up @@ -70,8 +69,6 @@ information.
validation behavior
- Configurable timeouts
- Configurable retry support
- Support for overriding the default `http.Client`
- Support for overriding default project-specific user agent

## Project Status

Expand Down Expand Up @@ -187,12 +184,6 @@ This is an example of a simple client application which uses this library.

File: [basic](./examples/basic/main.go)

#### Set custom user agent

This example illustrates setting a custom user agent.

File: [custom-user-agent](./examples/custom-user-agent/main.go)

#### Add an Action

This example illustrates adding an [`OpenUri Action`][msgcard-ref-actions] to
Expand Down
4 changes: 0 additions & 4 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ FEATURES

• Configurable retry support

• Support for overriding the default http.Client

• Support for overriding the default project-specific user agent


USAGE

Expand Down
52 changes: 0 additions & 52 deletions examples/custom-user-agent/main.go

This file was deleted.

35 changes: 0 additions & 35 deletions send.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ const ExpectedWebhookURLResponseText string = "1"
// before it times out and is cancelled.
const DefaultWebhookSendTimeout = 5 * time.Second

// DefaultUserAgent is the project-specific user agent used when submitting
// messages unless overridden by client code. This replaces the Go default
// user agent value of "Go-http-client/1.1".
//
// The major.minor numbers reflect when this project first diverged from the
// "upstream" or parent project.
const DefaultUserAgent string = "go-teams-notify/2.2"

// ErrWebhookURLUnexpected is returned when a provided webhook URL does
// not match a set of confirmed webhook URL patterns.
var ErrWebhookURLUnexpected = errors.New("webhook URL does not match one of expected patterns")
Expand All @@ -97,16 +89,13 @@ 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
SetUserAgent(userAgent string) API
SkipWebhookURLValidationOnSend(skip bool) API
AddWebhookURLValidationPatterns(patterns ...string) API
ValidateWebhook(webhookURL string) error
}

type teamsClient struct {
httpClient *http.Client
userAgent string
webhookURLValidationPatterns []string
skipWebhookURLValidation bool
}
Expand Down Expand Up @@ -144,22 +133,6 @@ 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
}

// SetUserAgent accepts a custom user agent string. This custom user agent is
// used when submitting messages to Microsoft Teams.
func (c *teamsClient) SetUserAgent(userAgent string) API {
c.userAgent = userAgent

return c
}

// AddWebhookURLValidationPatterns collects given patterns for validation of
// the webhook URL.
func (c *teamsClient) AddWebhookURLValidationPatterns(patterns ...string) API {
Expand Down Expand Up @@ -340,14 +313,6 @@ func (c teamsClient) prepareRequest(ctx context.Context, webhookURL string, prep

req.Header.Add("Content-Type", "application/json;charset=utf-8")

// If provided, override the project-specific user agent with custom value.
switch {
case c.userAgent != "":
req.Header.Set("User-Agent", c.userAgent)
default:
req.Header.Set("User-Agent", DefaultUserAgent)
}

return req, nil
}

Expand Down