Make `JiraClient.get()` accept optional query params
parent
3f58d01cdf
commit
0b9f5491d2
14
client.go
14
client.go
|
@ -26,13 +26,21 @@ type JiraClient struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c JiraClient) get(url string) ([]byte, error) {
|
func (c JiraClient) get(url string, queryParams map[string]string) ([]byte, error) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, err
|
return []byte{}, err
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(c.Username, c.Token)
|
req.SetBasicAuth(c.Username, c.Token)
|
||||||
|
|
||||||
|
if queryParams != nil {
|
||||||
|
q := req.URL.Query()
|
||||||
|
for k, v := range queryParams {
|
||||||
|
q.Add(k, v)
|
||||||
|
}
|
||||||
|
req.URL.RawQuery = q.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := c.Client.Do(req)
|
resp, err := c.Client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, err
|
return []byte{}, err
|
||||||
|
@ -48,7 +56,7 @@ func (c JiraClient) GetIssue(keyOrId string) (Issue, error) {
|
||||||
|
|
||||||
url := fmt.Sprintf("https://%s.atlassian.net/rest/api/2/issue/%s", c.Domain, keyOrId)
|
url := fmt.Sprintf("https://%s.atlassian.net/rest/api/2/issue/%s", c.Domain, keyOrId)
|
||||||
|
|
||||||
body, err := c.get(url)
|
body, err := c.get(url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return issue, err
|
return issue, err
|
||||||
}
|
}
|
||||||
|
@ -63,7 +71,7 @@ func (c JiraClient) GetProject(keyOrId string) (Project, error) {
|
||||||
|
|
||||||
url := fmt.Sprintf("https://%s.atlassian.net/rest/api/2/project/%s", c.Domain, keyOrId)
|
url := fmt.Sprintf("https://%s.atlassian.net/rest/api/2/project/%s", c.Domain, keyOrId)
|
||||||
|
|
||||||
body, err := c.get(url)
|
body, err := c.get(url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return project, err
|
return project, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue