Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
decode response json as a stream (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathany committed Apr 26, 2016
1 parent 8fc56b9 commit e1e7515
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions push/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -178,16 +177,12 @@ func (s *Service) PushBytes(deviceToken string, headers *Headers, payload []byte
return resp.Header.Get("apns-id"), nil
}

// read entire response body
// TODO: could decode while reading instead
body, err := ioutil.ReadAll(resp.Body)
var response response
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return "", err
}

var response response
json.Unmarshal(body, &response)

e, ok := errorReason[response.Reason]
if !ok {
// fallback to HTTP status codes if reason not found in JSON
Expand Down

0 comments on commit e1e7515

Please sign in to comment.