Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit adbfda4

Browse files
committed
response: simplify Decode
1 parent 65cd935 commit adbfda4

File tree

3 files changed

+5
-19
lines changed

3 files changed

+5
-19
lines changed

api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewLocalApi() (iface.CoreAPI, error) {
5353
func NewPathApi(ipfspath string) (iface.CoreAPI, error) {
5454
a, err := ApiAddr(ipfspath)
5555
if err != nil {
56-
if err == os.ErrNotExist {
56+
if os.IsNotExist(err) {
5757
err = nil
5858
}
5959
return nil, err

requestbuilder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ func (r *RequestBuilder) Exec(ctx context.Context, res interface{}) error {
110110
return lateErr
111111
}
112112

113-
return httpRes.Decode(res)
113+
return httpRes.decode(res)
114114
}

response.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,14 @@ func (r *Response) Cancel() error {
5959
return nil
6060
}
6161

62-
func (r *Response) Decode(dec interface{}) error {
62+
// Decode reads request body and decodes it as json
63+
func (r *Response) decode(dec interface{}) error {
6364
defer r.Close()
6465
if r.Error != nil {
6566
return r.Error
6667
}
6768

68-
n := 0
69-
var err error
70-
for {
71-
err = json.NewDecoder(r.Output).Decode(dec)
72-
if err != nil {
73-
break
74-
}
75-
n++
76-
}
77-
78-
// Decode expects at least one result. For calls where zero results are valid,
79-
// use Send and construct json Decoder manually.
80-
if n > 0 && err == io.EOF {
81-
err = nil
82-
}
83-
return err
69+
return json.NewDecoder(r.Output).Decode(dec)
8470
}
8571

8672
type Error struct {

0 commit comments

Comments
 (0)