Files
jira/attachment.go
Mike Pountney 27f57b2bbe Switch over to using github.com/go-jira/jira, from gopkg.in
There should be no reason to use gopkg.in versioned imports now that
we're using go modules. I think, IANAE.

gopkg.in kind of gets in the way of modules, as it only pulls over
tagged releases from github.com -- this then means that you need to use
go modules 'replace' syntax in the go.mod to use a non-versioned commit
or branch. This is feasible, but kind of ugly.

go modules defaults to pulling the latest version, so the default
behavior is the same as when pulling go-jira.v1 from gopkg.in.
2019-09-14 21:31:11 -07:00

47 lines
1.1 KiB
Go

package jira
import (
"encoding/json"
"github.com/go-jira/jira/jiradata"
)
// https://docs.atlassian.com/jira/REST/cloud/#api/2/attachment-getAttachment
func (j *Jira) GetAttachment(id string) (*jiradata.Attachment, error) {
return GetAttachment(j.UA, j.Endpoint, id)
}
func GetAttachment(ua HttpClient, endpoint string, id string) (*jiradata.Attachment, error) {
uri := URLJoin(endpoint, "rest/api/2/attachment", id)
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode == 200 {
results := &jiradata.Attachment{}
return results, json.NewDecoder(resp.Body).Decode(results)
}
return nil, responseError(resp)
}
// https://docs.atlassian.com/jira/REST/cloud/#api/2/attachment-removeAttachment
func (j *Jira) RemoveAttachment(id string) error {
return RemoveAttachment(j.UA, j.Endpoint, id)
}
func RemoveAttachment(ua HttpClient, endpoint string, id string) error {
uri := URLJoin(endpoint, "rest/api/2/attachment", id)
resp, err := ua.Delete(uri)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode == 204 {
return nil
}
return responseError(resp)
}