Skip to content

Commit

Permalink
Replace ioutil.ReadAll with a buffered decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Oct 5, 2020
1 parent b759691 commit 05e314e
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions accounts/pkg/storage/cs3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"path"
"strings"
Expand Down Expand Up @@ -93,17 +92,13 @@ func (r CS3Repo) LoadAccount(ctx context.Context, id string, a *proto.Account) (
return &notFoundErr{"account", id}
}

b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
defer resp.Body.Close()

if err := json.Unmarshal(b, &a); err != nil {
dec := json.NewDecoder(resp.Body)
var b []byte
if err = dec.Decode(&b); err != nil {
return err
}

return nil
return json.Unmarshal(b, &a)
}

// DeleteAccount deletes an account via cs3 by id
Expand Down Expand Up @@ -170,13 +165,12 @@ func (r CS3Repo) LoadGroup(ctx context.Context, id string, g *proto.Group) (err
return &notFoundErr{"group", id}
}

b, err := ioutil.ReadAll(resp.Body)
if err != nil {
defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
var b []byte
if err = dec.Decode(&b); err != nil {
return err
}

defer resp.Body.Close()

return json.Unmarshal(b, &g)
}

Expand Down

0 comments on commit 05e314e

Please sign in to comment.