Skip to content

Commit

Permalink
Simplify deserialization logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Mara committed Jun 28, 2018
1 parent bd60d4e commit 77ea07b
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions component.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

0 comments on commit 77ea07b

Please sign in to comment.