Skip to content

Commit

Permalink
Removed close on body response
Browse files Browse the repository at this point in the history
  • Loading branch information
thamerkhamassi authored and zeddo123 committed Dec 3, 2024
1 parent c9a2588 commit 9453075
Showing 1 changed file with 7 additions and 51 deletions.
58 changes: 7 additions & 51 deletions gosap.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,17 +441,10 @@ func (s *Session) GetInventoryCounting(cfg Config, id int) (*InventoryCounting,
return nil, err
}

resp, err := s.Do(req)
_, content, err := s.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

// Read the response body
content, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("could not read response body content due to %s", err)
}

var inventoryCounting InventoryCounting

Expand All @@ -473,17 +466,10 @@ func (s *Session) getInventoryCountings(cfg Config, endpoint string) ([]Inventor
return nil, err
}

resp, err := s.Do(req)
_, content, err := s.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()

// Read the response body
content, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("could not read response body content due to %s", err)
}

// Unmarshal the JSON into the wrapper struct
var response InventoryCountingResponse
Expand Down Expand Up @@ -514,13 +500,7 @@ func (s *Session) CreateInventoryCounting(cfg Config, counting InventoryCounting
return false, err
}

resp, err := s.Do(req)
if err != nil {
return false, err
}
defer resp.Body.Close()

_, err = io.ReadAll(resp.Body)
_, _, err = s.Do(req)
if err != nil {
return false, fmt.Errorf("could not read response body content due to %s", err)
}
Expand All @@ -540,13 +520,7 @@ func (s *Session) UpdateInventoryCounting(cfg Config, id int, updates InventoryC
return false, err
}

resp, err := s.Do(req)
if err != nil {
return false, err
}
defer resp.Body.Close()

_, err = io.ReadAll(resp.Body)
_, _, err = s.Do(req)
if err != nil {
return false, fmt.Errorf("could not read response body content due to %s", err)
}
Expand All @@ -561,13 +535,7 @@ func (s *Session) DeleteInventoryCounting(cfg Config, id int) (bool, error) {
return false, err
}

resp, err := s.Do(req)
if err != nil {
return false, err
}
defer resp.Body.Close()

_, err = io.ReadAll(resp.Body)
_, _, err = s.Do(req)
if err != nil {
return false, fmt.Errorf("could not read response body content due to %s", err)
}
Expand All @@ -582,13 +550,7 @@ func (s *Session) CloseInventoryCounting(cfg Config, id int) (bool, error) {
return false, err
}

resp, err := s.Do(req)
if err != nil {
return false, err
}
defer resp.Body.Close()

_, err = io.ReadAll(resp.Body)
_, _, err = s.Do(req)
if err != nil {
return false, fmt.Errorf("could not read response body content due to %s", err)
}
Expand Down Expand Up @@ -619,13 +581,7 @@ func (s *Session) AddLinesToInventoryCounting(cfg Config, id int, lines []Invent
return false, err
}

resp, err := s.Do(req)
if err != nil {
return false, err
}
defer resp.Body.Close()

_, err = io.ReadAll(resp.Body)
_, _, err = s.Do(req)
if err != nil {
return false, fmt.Errorf("could not read response body content due to %s", err)
}
Expand Down

0 comments on commit 9453075

Please sign in to comment.