mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-11-06 08:49:11 +02:00
feat: Replace http.Client with interface for extensibility
Setting up the NewClient method to accept an interface that gives access to the Do method of the http.Client rather than using a hard http.Client so that an interface can be passed for mocking and other non-standard clients can be used with go-jira.
This commit is contained in:
committed by
Wes McNamee
parent
9ca8940d2f
commit
b59a65c365
12
jira.go
12
jira.go
@@ -15,15 +15,21 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// httpClient defines an interface for an http.Client implementation so that alternative
|
||||||
|
// http Clients can be passed in for making requests
|
||||||
|
type httpClient interface {
|
||||||
|
Do(request *http.Request) (response *http.Response, err error)
|
||||||
|
}
|
||||||
|
|
||||||
// A Client manages communication with the JIRA API.
|
// A Client manages communication with the JIRA API.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
// HTTP client used to communicate with the API.
|
// HTTP client used to communicate with the API.
|
||||||
client *http.Client
|
client httpClient
|
||||||
|
|
||||||
// Base URL for API requests.
|
// Base URL for API requests.
|
||||||
baseURL *url.URL
|
baseURL *url.URL
|
||||||
|
|
||||||
// Session storage if the user authentificate with a Session cookie
|
// Session storage if the user authenticates with a Session cookie
|
||||||
session *Session
|
session *Session
|
||||||
|
|
||||||
// Services used for talking to different parts of the JIRA API.
|
// Services used for talking to different parts of the JIRA API.
|
||||||
@@ -52,7 +58,7 @@ type Client struct {
|
|||||||
// As an alternative you can use Session Cookie based authentication provided by this package as well.
|
// As an alternative you can use Session Cookie based authentication provided by this package as well.
|
||||||
// See https://docs.atlassian.com/jira/REST/latest/#authentication
|
// See https://docs.atlassian.com/jira/REST/latest/#authentication
|
||||||
// baseURL is the HTTP endpoint of your JIRA instance and should always be specified with a trailing slash.
|
// baseURL is the HTTP endpoint of your JIRA instance and should always be specified with a trailing slash.
|
||||||
func NewClient(httpClient *http.Client, baseURL string) (*Client, error) {
|
func NewClient(httpClient httpClient, baseURL string) (*Client, error) {
|
||||||
if httpClient == nil {
|
if httpClient == nil {
|
||||||
httpClient = http.DefaultClient
|
httpClient = http.DefaultClient
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user