mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-03-19 20:57:47 +02:00
Simplify deserialization logic
This commit is contained in:
parent
bd60d4e7da
commit
77ea07b2ce
24
component.go
24
component.go
@ -1,11 +1,5 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// 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
|
||||
@ -32,21 +26,9 @@ func (s *ComponentService) Create(options *CreateComponentOptions) (*ProjectComp
|
||||
if err != nil {
|
||||
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)
|
||||
defer resp.Body.Close()
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
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
|
||||
resp, err := s.client.Do(req, component)
|
||||
|
||||
return component, resp, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user