Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed usage of deprecated io/ioutil package #1293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix: # Support latest and one minor back
go: ["1.17", "1.18", "1.19"]
go: ["1.18", "1.19", "1.20", "1.21", "1.22"]
env:
GOFLAGS: -mod=readonly

Expand Down
4 changes: 2 additions & 2 deletions circuitbreaker/hystrix_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package circuitbreaker_test

import (
"io/ioutil"
"io"
stdlog "log"
"testing"
"time"
Expand All @@ -12,7 +12,7 @@ import (
)

func TestHystrix(t *testing.T) {
stdlog.SetOutput(ioutil.Discard)
stdlog.SetOutput(io.Discard)

const (
commandName = "my-endpoint"
Expand Down
4 changes: 2 additions & 2 deletions metrics/generic/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"go/parser"
"go/token"
"go/types"
"io/ioutil"
"math"
"math/rand"
"os"
"sync"
"testing"

Expand Down Expand Up @@ -119,7 +119,7 @@ func TestSimpleHistogram(t *testing.T) {
// But currently works for Counter and Gauge.
// To have a more solid test, this test should be removed and the other tests should be run on a 32-bit arch.
func TestAtomicAlignment(t *testing.T) {
content, err := ioutil.ReadFile("./generic.go")
content, err := os.ReadFile("./generic.go")
if err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 5 additions & 5 deletions metrics/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package prometheus

import (
"io/ioutil"
"io"
"math"
"math/rand"
"net/http"
Expand All @@ -23,7 +23,7 @@ func TestCounter(t *testing.T) {

scrape := func() string {
resp, _ := http.Get(s.URL)
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
return string(buf)
}

Expand Down Expand Up @@ -54,7 +54,7 @@ func TestGauge(t *testing.T) {

scrape := func() string {
resp, _ := http.Get(s.URL)
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
return string(buf)
}

Expand Down Expand Up @@ -85,7 +85,7 @@ func TestSummary(t *testing.T) {

scrape := func() string {
resp, _ := http.Get(s.URL)
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
return string(buf)
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func TestHistogram(t *testing.T) {

scrape := func() string {
resp, _ := http.Get(s.URL)
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
return string(buf)
}

Expand Down
4 changes: 2 additions & 2 deletions sd/etcd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"crypto/tls"
"crypto/x509"
"errors"
"io/ioutil"
"net"
"net/http"
"os"
"time"

etcd "go.etcd.io/etcd/client/v2"
Expand Down Expand Up @@ -81,7 +81,7 @@ func NewClient(ctx context.Context, machines []string, options ClientOptions) (C
if err != nil {
return nil, err
}
caCertCt, err := ioutil.ReadFile(options.CACert)
caCertCt, err := os.ReadFile(options.CACert)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions transport/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"encoding/xml"
"io"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -180,7 +179,7 @@ func EncodeJSONRequest(c context.Context, r *http.Request, request interface{})
}
}
var b bytes.Buffer
r.Body = ioutil.NopCloser(&b)
r.Body = io.NopCloser(&b)
return json.NewEncoder(&b).Encode(request)
}

Expand All @@ -195,7 +194,7 @@ func EncodeXMLRequest(c context.Context, r *http.Request, request interface{}) e
}
}
var b bytes.Buffer
r.Body = ioutil.NopCloser(&b)
r.Body = io.NopCloser(&b)
return xml.NewEncoder(&b).Encode(request)
}

Expand Down
9 changes: 4 additions & 5 deletions transport/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -205,7 +204,7 @@ func TestEncodeJSONRequest(t *testing.T) {
var body string

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil && err != io.EOF {
t.Fatal(err)
}
Expand Down Expand Up @@ -266,7 +265,7 @@ func TestSetClient(t *testing.T) {
var (
encode = func(context.Context, *http.Request, interface{}) error { return nil }
decode = func(_ context.Context, r *http.Response) (interface{}, error) {
t, err := ioutil.ReadAll(r.Body)
t, err := io.ReadAll(r.Body)
if err != nil {
return nil, err
}
Expand All @@ -278,7 +277,7 @@ func TestSetClient(t *testing.T) {
return &http.Response{
StatusCode: http.StatusOK,
Request: req,
Body: ioutil.NopCloser(bytes.NewBufferString("hello, world!")),
Body: io.NopCloser(bytes.NewBufferString("hello, world!")),
}, nil
})

Expand Down Expand Up @@ -311,7 +310,7 @@ func TestNewExplicitClient(t *testing.T) {
}

dec := func(_ context.Context, resp *http.Response) (response interface{}, err error) {
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
resp.Body.Close()
return string(buf), err
}
Expand Down
4 changes: 2 additions & 2 deletions transport/http/jsonrpc/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"
"net/url"
"sync/atomic"
Expand Down Expand Up @@ -179,7 +179,7 @@ func (c Client) Endpoint() endpoint.Endpoint {

req.Header.Set("Content-Type", "application/json; charset=utf-8")
var b bytes.Buffer
req.Body = ioutil.NopCloser(&b)
req.Body = io.NopCloser(&b)
err = json.NewEncoder(&b).Encode(rpcReq)
if err != nil {
return nil, err
Expand Down
5 changes: 2 additions & 3 deletions transport/http/jsonrpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -169,7 +168,7 @@ func TestClientHappyPath(t *testing.T) {
t.Fatal("Header not set by before func.")
}

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil && err != io.EOF {
t.Fatal(err)
}
Expand Down Expand Up @@ -248,7 +247,7 @@ func TestCanUseDefaults(t *testing.T) {
)

server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil && err != io.EOF {
t.Fatal(err)
}
Expand Down
13 changes: 6 additions & 7 deletions transport/http/jsonrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestServerBadDecode(t *testing.T) {
server := httptest.NewServer(handler)
defer server.Close()
resp, _ := http.Post(server.URL, "application/json", addBody())
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
if want, have := http.StatusOK, resp.StatusCode; want != have {
t.Errorf("want %d, have %d: %s", want, have, buf)
}
Expand All @@ -124,7 +123,7 @@ func TestServerBadEndpoint(t *testing.T) {
if want, have := http.StatusOK, resp.StatusCode; want != have {
t.Errorf("want %d, have %d", want, have)
}
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
expectErrorCode(t, jsonrpc.InternalError, buf)
expectValidRequestID(t, 1, buf)
}
Expand All @@ -144,7 +143,7 @@ func TestServerBadEncode(t *testing.T) {
if want, have := http.StatusOK, resp.StatusCode; want != have {
t.Errorf("want %d, have %d", want, have)
}
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
expectErrorCode(t, jsonrpc.InternalError, buf)
expectValidRequestID(t, 1, buf)
}
Expand Down Expand Up @@ -196,7 +195,7 @@ func TestCanRejectInvalidJSON(t *testing.T) {
if want, have := http.StatusOK, resp.StatusCode; want != have {
t.Errorf("want %d, have %d", want, have)
}
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
expectErrorCode(t, jsonrpc.ParseError, buf)
expectNilRequestID(t, buf)
}
Expand All @@ -210,7 +209,7 @@ func TestServerUnregisteredMethod(t *testing.T) {
if want, have := http.StatusOK, resp.StatusCode; want != have {
t.Errorf("want %d, have %d", want, have)
}
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
expectErrorCode(t, jsonrpc.MethodNotFoundError, buf)
}

Expand All @@ -219,7 +218,7 @@ func TestServerHappyPath(t *testing.T) {
step()
resp := <-response
defer resp.Body.Close() // nolint
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
if want, have := http.StatusOK, resp.StatusCode; want != have {
t.Errorf("want %d, have %d (%s)", want, have, buf)
}
Expand Down
4 changes: 2 additions & 2 deletions transport/http/proto/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"io"
"net/http"

httptransport "github.com/go-kit/kit/transport/http"
Expand Down Expand Up @@ -32,6 +32,6 @@ func EncodeProtoRequest(_ context.Context, r *http.Request, preq interface{}) er
return err
}
r.ContentLength = int64(len(b))
r.Body = ioutil.NopCloser(bytes.NewReader(b))
r.Body = io.NopCloser(bytes.NewReader(b))
return nil
}
6 changes: 3 additions & 3 deletions transport/http/proto/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package proto

import (
"context"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -27,7 +27,7 @@ func TestEncodeProtoRequest(t *testing.T) {
return
}

bod, err := ioutil.ReadAll(r.Body)
bod, err := io.ReadAll(r.Body)
if err != nil {
t.Errorf("expected no read errors but got: %s", err)
return
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestEncodeProtoResponse(t *testing.T) {
return
}

bod, err := ioutil.ReadAll(w.Body)
bod, err := io.ReadAll(w.Body)
if err != nil {
t.Errorf("expected no read errors but got: %s", err)
return
Expand Down
12 changes: 6 additions & 6 deletions transport/http/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package http_test
import (
"context"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestServerHappyPath(t *testing.T) {
step()
resp := <-response
defer resp.Body.Close()
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
if want, have := http.StatusOK, resp.StatusCode; want != have {
t.Errorf("want %d, have %d (%s)", want, have, buf)
}
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestEncodeJSONResponse(t *testing.T) {
if want, have := "Snowden", resp.Header.Get("X-Edward"); want != have {
t.Errorf("X-Edward: want %q, have %q", want, have)
}
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
if want, have := `{"foo":"bar"}`, strings.TrimSpace(string(buf)); want != have {
t.Errorf("Body: want %s, have %s", want, have)
}
Expand Down Expand Up @@ -327,7 +327,7 @@ func TestAddMultipleHeadersErrorEncoder(t *testing.T) {
t.Errorf("Header: unexpected header %s: %v", k, expect[k])
}
}
if b, _ := ioutil.ReadAll(resp.Body); errStr != string(b) {
if b, _ := io.ReadAll(resp.Body); errStr != string(b) {
t.Errorf("ErrorEncoder: got: %q, expected: %q", b, errStr)
}
}
Expand All @@ -353,7 +353,7 @@ func TestEncodeNoContent(t *testing.T) {
if want, have := http.StatusNoContent, resp.StatusCode; want != have {
t.Errorf("StatusCode: want %d, have %d", want, have)
}
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
if want, have := 0, len(buf); want != have {
t.Errorf("Body: want no content, have %d bytes", have)
}
Expand Down Expand Up @@ -387,7 +387,7 @@ func TestEnhancedError(t *testing.T) {
if want, have := "1", resp.Header.Get("X-Enhanced"); want != have {
t.Errorf("X-Enhanced: want %q, have %q", want, have)
}
buf, _ := ioutil.ReadAll(resp.Body)
buf, _ := io.ReadAll(resp.Body)
if want, have := `{"err":"enhanced"}`, strings.TrimSpace(string(buf)); want != have {
t.Errorf("Body: want %s, have %s", want, have)
}
Expand Down
Loading
Loading