Make `JiraClient.get()` accept optional query params

main
Jasper Bok 2023-07-17 20:34:00 +02:00
parent 3f58d01cdf
commit 0b9f5491d2
1 changed files with 11 additions and 3 deletions

View File

@ -26,13 +26,21 @@ type JiraClient struct {
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)
if err != nil {
return []byte{}, err
}
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)
if err != nil {
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)
body, err := c.get(url)
body, err := c.get(url, nil)
if err != nil {
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)
body, err := c.get(url)
body, err := c.get(url, nil)
if err != nil {
return project, err
}