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

client: allow overriding the api endpoint #173

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ var defaultHTTPClient HTTPClient = newDefaultHTTPClient()

// Client wraps http client
type Client struct {
authToken string
authToken string
apiEndpoint string

// HTTPClient is the HTTP client used for making requests against the
// PagerDuty API. You can use either *http.Client here, or your own
Expand All @@ -96,8 +97,9 @@ type Client struct {
// NewClient creates an API client
func NewClient(authToken string) *Client {
return &Client{
authToken: authToken,
HTTPClient: defaultHTTPClient,
authToken: authToken,
apiEndpoint: apiEndpoint,
HTTPClient: defaultHTTPClient,
}
}

Expand Down Expand Up @@ -130,7 +132,7 @@ func (c *Client) get(path string) (*http.Response, error) {
}

func (c *Client) do(method, path string, body io.Reader, headers *map[string]string) (*http.Response, error) {
endpoint := apiEndpoint + path
endpoint := c.apiEndpoint + path
req, _ := http.NewRequest(method, endpoint, body)
req.Header.Set("Accept", "application/vnd.pagerduty+json;version=2")
if headers != nil {
Expand Down