Skip to content

Commit

Permalink
🧹 replace ioutil with io package (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock authored Mar 28, 2023
1 parent 135247b commit 825a56b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
6 changes: 3 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"strconv"

Expand Down Expand Up @@ -106,7 +106,7 @@ func (c *Client) DoClientRequest(ctx context.Context, client HTTPClient, url str
log.Debug().Str("body", spb.Message).Int("status", resp.StatusCode).Msg("non-ok http request")
return status.FromProto(spb).Err()
} else {
payload, err := ioutil.ReadAll(reader)
payload, err := io.ReadAll(reader)
if err != nil {
log.Error().Err(err).Msg("could not parse http body")
}
Expand All @@ -118,7 +118,7 @@ func (c *Client) DoClientRequest(ctx context.Context, client HTTPClient, url str
return errors.Wrap(err, "aborted because context was done")
}

respBodyBytes, err := ioutil.ReadAll(resp.Body)
respBodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return errors.Wrap(err, "failed to read response body")
}
Expand Down
3 changes: 1 addition & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ranger

import (
"io"
"io/ioutil"
"net/http"

"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -51,7 +50,7 @@ func HttpError(w http.ResponseWriter, req *http.Request, err error) {

// parseStatus tries to parse the proto Status from the body of the response.
func parseStatus(reader io.Reader) (*spb.Status, error) {
payload, err := ioutil.ReadAll(reader)
payload, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions examples/oneof/oneof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package oneof
import (
"bytes"
"context"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestOneOfJSON(t *testing.T) {

// check response
r := &OneOfReply{}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
require.NoError(t, err)
err = jsonpb.Unmarshal(data, r)
assert.Nil(t, err)
Expand All @@ -106,7 +106,7 @@ func TestOneOfJSON(t *testing.T) {

// check response
r := &OneOfReply{}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
require.NoError(t, err)
err = jsonpb.Unmarshal(data, r)
assert.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ranger
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -104,7 +104,7 @@ func (s *server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// the context. It also adds the http headers to the context.
func preProcessRequest(ctx context.Context, req *http.Request) (context.Context, context.CancelFunc, []byte, error) {
// read body content
body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
defer req.Body.Close()
if err != nil {
return nil, nil, nil, status.Error(codes.DataLoss, "unrecoverable data loss or corruption")
Expand Down
8 changes: 3 additions & 5 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -62,7 +61,6 @@ func TestRangerHttpServer(t *testing.T) {
srv.ServeHTTP(w, req)
resp = w.Result()
assert.Equal(t, 200, resp.StatusCode, "correct status code")

}

func TestRangerHttpHeader(t *testing.T) {
Expand Down Expand Up @@ -97,7 +95,7 @@ func TestRangerHttpHeader(t *testing.T) {
resp = w.Result()
assert.Equal(t, 200, resp.StatusCode, "correct status code")

content, err := ioutil.ReadAll(w.Body)
content, err := io.ReadAll(w.Body)
assert.Nil(t, err, "should return protobuf content")

var msg pingpong.PongReply
Expand All @@ -117,7 +115,7 @@ func runStatusCall(srv http.Handler, path string) *http.Response {
}

func parseStatus(reader io.Reader) (*spb.Status, error) {
payload, err := ioutil.ReadAll(reader)
payload, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -163,7 +161,7 @@ func TestRangerErrorHandling(t *testing.T) {
srv.ServeHTTP(w, req)
resp = w.Result()
assert.Equal(t, 400, resp.StatusCode, "correct status code")
payload, err := ioutil.ReadAll(resp.Body)
payload, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 825a56b

Please sign in to comment.