mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-07-13 01:00:23 +02:00
Simplify deserialization logic
This commit is contained in:
24
component.go
24
component.go
@ -1,11 +1,5 @@
|
|||||||
package jira
|
package jira
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ComponentService handles components for the JIRA instance / API.
|
// ComponentService handles components for the JIRA instance / API.
|
||||||
//
|
//
|
||||||
// JIRA API docs: https://docs.atlassian.com/software/jira/docs/api/REST/7.10.1/#api/2/component
|
// JIRA API docs: https://docs.atlassian.com/software/jira/docs/api/REST/7.10.1/#api/2/component
|
||||||
@ -32,21 +26,9 @@ func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComp
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
resp, err := s.client.Do(req, nil)
|
|
||||||
if err != nil {
|
|
||||||
// incase of error return the resp for further inspection
|
|
||||||
return nil, resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
component := new(ProjectComponent)
|
component := new(ProjectComponent)
|
||||||
defer resp.Body.Close()
|
resp, err := s.client.Do(req, component)
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
return component, resp, err
|
||||||
return nil, resp, fmt.Errorf("Could not read the returned data")
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(data, component)
|
|
||||||
if err != nil {
|
|
||||||
return nil, resp, fmt.Errorf("Could not unmarshall the data into struct")
|
|
||||||
}
|
|
||||||
return component, resp, nil
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user