Skip to content

Commit

Permalink
feat(remote): Deserialize response from remote using json.Decode
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop committed Apr 2, 2019
1 parent 7f3d8bc commit 2d73e84
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions lib/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/qri-io/dag"
"github.com/qri-io/dag/dsync"
"github.com/qri-io/qri/actions"
"github.com/qri-io/qri/base/fill"
"github.com/qri-io/qri/p2p"
"github.com/qri-io/qri/repo"

Expand Down Expand Up @@ -91,27 +90,11 @@ func (r *RemoteRequests) PushToRemote(p *PushParams, out *bool) error {
return fmt.Errorf("error code %d: %v", res.StatusCode, rejectionReason(res.Body))
}

bodyBytes, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}

var bodyResponse map[string]interface{}
err = json.Unmarshal(bodyBytes, &bodyResponse)
if err != nil {
return err
}

dataResponse, ok := bodyResponse["data"].(map[string]interface{})
if !ok {
return fmt.Errorf("expected: data json")
}

var result ReceiveResult
err = fill.Struct(dataResponse, &result)
if err != nil {
env := struct{Data ReceiveResult}{}
if err := json.NewDecoder(res.Body).Decode(&env); err != nil {
return err
}
res.Body.Close()

ctx := context.Background()

Expand All @@ -129,7 +112,7 @@ func (r *RemoteRequests) PushToRemote(p *PushParams, out *bool) error {
return err
}

err = send.PerformSend(result.SessionID, dinfo.Manifest, result.Diff)
err = send.PerformSend(env.Data.SessionID, dinfo.Manifest, env.Data.Diff)
if err != nil {
return err
}
Expand Down

0 comments on commit 2d73e84

Please sign in to comment.