Skip to content

Commit 2d73e84

Browse files
committed
feat(remote): Deserialize response from remote using json.Decode
1 parent 7f3d8bc commit 2d73e84

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

lib/remote.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/qri-io/dag"
1414
"github.com/qri-io/dag/dsync"
1515
"github.com/qri-io/qri/actions"
16-
"github.com/qri-io/qri/base/fill"
1716
"github.com/qri-io/qri/p2p"
1817
"github.com/qri-io/qri/repo"
1918

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

94-
bodyBytes, err := ioutil.ReadAll(res.Body)
95-
if err != nil {
96-
return err
97-
}
98-
99-
var bodyResponse map[string]interface{}
100-
err = json.Unmarshal(bodyBytes, &bodyResponse)
101-
if err != nil {
102-
return err
103-
}
104-
105-
dataResponse, ok := bodyResponse["data"].(map[string]interface{})
106-
if !ok {
107-
return fmt.Errorf("expected: data json")
108-
}
109-
110-
var result ReceiveResult
111-
err = fill.Struct(dataResponse, &result)
112-
if err != nil {
93+
env := struct{Data ReceiveResult}{}
94+
if err := json.NewDecoder(res.Body).Decode(&env); err != nil {
11395
return err
11496
}
97+
res.Body.Close()
11598

11699
ctx := context.Background()
117100

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

132-
err = send.PerformSend(result.SessionID, dinfo.Manifest, result.Diff)
115+
err = send.PerformSend(env.Data.SessionID, dinfo.Manifest, env.Data.Diff)
133116
if err != nil {
134117
return err
135118
}

0 commit comments

Comments
 (0)