Skip to content

Commit da56347

Browse files
committed
clear golangci-lint warnings/errors
1 parent 93d335a commit da56347

15 files changed

+57
-71
lines changed

client/keepalive.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package client
22

33
import (
44
"io"
5-
"io/ioutil"
65
"net/http"
76
"sync/atomic"
87
)
@@ -50,7 +49,7 @@ func (d *drainingReadCloser) Close() error {
5049
// some bytes, but the closer ignores them to keep the underling
5150
// connection open.
5251
//nolint:errcheck
53-
io.Copy(ioutil.Discard, d.rdr)
52+
io.Copy(io.Discard, d.rdr)
5453
}
5554
return d.rdr.Close()
5655
}

client/keepalive_test.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package client
33
import (
44
"bytes"
55
"io"
6-
"io/ioutil"
76
"testing"
87

98
"github.com/stretchr/testify/assert"
@@ -39,10 +38,10 @@ func (c *countingReadCloser) Close() error {
3938

4039
func TestDrainingReadCloser(t *testing.T) {
4140
rdr := newCountingReader(bytes.NewBufferString("There are many things to do"), false)
42-
prevDisc := ioutil.Discard
41+
prevDisc := io.Discard
4342
disc := bytes.NewBuffer(nil)
44-
ioutil.Discard = disc
45-
defer func() { ioutil.Discard = prevDisc }()
43+
io.Discard = disc
44+
defer func() { io.Discard = prevDisc }()
4645

4746
buf := make([]byte, 5)
4847
ts := &drainingReadCloser{rdr: rdr}
@@ -57,10 +56,10 @@ func TestDrainingReadCloser(t *testing.T) {
5756

5857
func TestDrainingReadCloser_SeenEOF(t *testing.T) {
5958
rdr := newCountingReader(bytes.NewBufferString("There are many things to do"), true)
60-
prevDisc := ioutil.Discard
59+
prevDisc := io.Discard
6160
disc := bytes.NewBuffer(nil)
62-
ioutil.Discard = disc
63-
defer func() { ioutil.Discard = prevDisc }()
61+
io.Discard = disc
62+
defer func() { io.Discard = prevDisc }()
6463

6564
buf := make([]byte, 5)
6665
ts := &drainingReadCloser{rdr: rdr}

client/opentelemetry.go

-5
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,3 @@ func newConfig(opts ...OpenTelemetryOpt) *config {
205205
func version() string {
206206
return instrumentationVersion
207207
}
208-
209-
// SemVersion is the semantic version to be supplied to tracer/meter creation.
210-
func semVersion() string {
211-
return "semver:" + version()
212-
}

client/opentelemetry_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func Test_injectOpenTelemetrySpanContext(t *testing.T) {
9191
header := map[string][]string{}
9292
tr := newOpenTelemetryTransport(&mockRuntime{runtime.TestClientRequest{Headers: header}}, "", nil)
9393
tr.config.Propagator = propagation.TraceContext{}
94-
tr.Submit(operation)
94+
_, err := tr.Submit(operation)
95+
assert.NoError(t, err)
9596

9697
assert.Len(t, header, 1)
9798
}

client/opentracing_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"context"
66
"io"
7-
"io/ioutil"
87
"testing"
98

109
"github.com/go-openapi/strfmt"
@@ -33,7 +32,7 @@ func (r tres) GetHeaders(_ string) []string {
3332
return []string{"the headers", "the headers2"}
3433
}
3534
func (r tres) Body() io.ReadCloser {
36-
return ioutil.NopCloser(bytes.NewBufferString("the content"))
35+
return io.NopCloser(bytes.NewBufferString("the content"))
3736
}
3837

3938
type mockRuntime struct {

client/request_test.go

+17-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"encoding/xml"
2121
"errors"
2222
"io"
23-
"io/ioutil"
2423
"mime"
2524
"mime/multipart"
2625
"net/http"
@@ -165,7 +164,7 @@ func TestBuildRequest_BuildHTTP_Payload(t *testing.T) {
165164
assert.Equal(t, "world", req.URL.Query().Get("hello"))
166165
assert.Equal(t, "/flats/1234/", req.URL.Path)
167166
expectedBody, _ := json.Marshal(bd)
168-
actualBody, _ := ioutil.ReadAll(req.Body)
167+
actualBody, _ := io.ReadAll(req.Body)
169168
assert.Equal(t, append(expectedBody, '\n'), actualBody)
170169
}
171170
}
@@ -197,7 +196,7 @@ func TestBuildRequest_BuildHTTP_SetsInAuth(t *testing.T) {
197196
assert.Equal(t, "world", req.URL.Query().Get("hello"))
198197
assert.Equal(t, "/flats/1234/", req.URL.Path)
199198
expectedBody, _ := json.Marshal(bd)
200-
actualBody, _ := ioutil.ReadAll(req.Body)
199+
actualBody, _ := io.ReadAll(req.Body)
201200
assert.Equal(t, append(expectedBody, '\n'), actualBody)
202201
}
203202
}
@@ -224,7 +223,7 @@ func TestBuildRequest_BuildHTTP_XMLPayload(t *testing.T) {
224223
assert.Equal(t, "world", req.URL.Query().Get("hello"))
225224
assert.Equal(t, "/flats/1234/", req.URL.Path)
226225
expectedBody, _ := xml.Marshal(bd)
227-
actualBody, _ := ioutil.ReadAll(req.Body)
226+
actualBody, _ := io.ReadAll(req.Body)
228227
assert.Equal(t, expectedBody, actualBody)
229228
}
230229
}
@@ -247,7 +246,7 @@ func TestBuildRequest_BuildHTTP_TextPayload(t *testing.T) {
247246
assert.Equal(t, "world", req.URL.Query().Get("hello"))
248247
assert.Equal(t, "/flats/1234/", req.URL.Path)
249248
expectedBody := []byte(bd)
250-
actualBody, _ := ioutil.ReadAll(req.Body)
249+
actualBody, _ := io.ReadAll(req.Body)
251250
assert.Equal(t, expectedBody, actualBody)
252251
}
253252
}
@@ -269,7 +268,7 @@ func TestBuildRequest_BuildHTTP_Form(t *testing.T) {
269268
assert.Equal(t, "world", req.URL.Query().Get("hello"))
270269
assert.Equal(t, "/flats/1234/", req.URL.Path)
271270
expected := []byte("something=some+value")
272-
actual, _ := ioutil.ReadAll(req.Body)
271+
actual, _ := io.ReadAll(req.Body)
273272
assert.Equal(t, expected, actual)
274273
}
275274
}
@@ -292,7 +291,7 @@ func TestBuildRequest_BuildHTTP_Form_URLEncoded(t *testing.T) {
292291
assert.Equal(t, "world", req.URL.Query().Get("hello"))
293292
assert.Equal(t, "/flats/1234/", req.URL.Path)
294293
expected := []byte("something=some+value")
295-
actual, _ := ioutil.ReadAll(req.Body)
294+
actual, _ := io.ReadAll(req.Body)
296295
assert.Equal(t, expected, actual)
297296
}
298297
}
@@ -316,7 +315,7 @@ func TestBuildRequest_BuildHTTP_Form_Content_Length(t *testing.T) {
316315
assert.Condition(t, func() bool { return req.ContentLength > 0 },
317316
"ContentLength must great than 0. got %d", req.ContentLength)
318317
expected := []byte("something=some+value")
319-
actual, _ := ioutil.ReadAll(req.Body)
318+
actual, _ := io.ReadAll(req.Body)
320319
assert.Equal(t, expected, actual)
321320
}
322321
}
@@ -339,7 +338,7 @@ func TestBuildRequest_BuildHTTP_FormMultipart(t *testing.T) {
339338
assert.Equal(t, "/flats/1234/", req.URL.Path)
340339
expected1 := []byte("Content-Disposition: form-data; name=\"something\"")
341340
expected2 := []byte("some value")
342-
actual, _ := ioutil.ReadAll(req.Body)
341+
actual, _ := io.ReadAll(req.Body)
343342
actuallines := bytes.Split(actual, []byte("\r\n"))
344343
assert.Equal(t, 6, len(actuallines))
345344
boundary := string(actuallines[0])
@@ -371,7 +370,7 @@ func TestBuildRequest_BuildHTTP_FormMultiples(t *testing.T) {
371370
expected1 := []byte("Content-Disposition: form-data; name=\"something\"")
372371
expected2 := []byte("some value")
373372
expected3 := []byte("another value")
374-
actual, _ := ioutil.ReadAll(req.Body)
373+
actual, _ := io.ReadAll(req.Body)
375374
actuallines := bytes.Split(actual, []byte("\r\n"))
376375
assert.Equal(t, 10, len(actuallines))
377376
boundary := string(actuallines[0])
@@ -388,8 +387,8 @@ func TestBuildRequest_BuildHTTP_FormMultiples(t *testing.T) {
388387
}
389388

390389
func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
391-
cont, _ := ioutil.ReadFile("./runtime.go")
392-
cont2, _ := ioutil.ReadFile("./request.go")
390+
cont, _ := os.ReadFile("./runtime.go")
391+
cont2, _ := os.ReadFile("./request.go")
393392
reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
394393
_ = req.SetFormParam("something", "some value")
395394
_ = req.SetFileParam("file", mustGetFile("./runtime.go"))
@@ -420,7 +419,7 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
420419
mpf, _ := mpff.Open()
421420
defer mpf.Close()
422421
assert.Equal(t, filename, mpff.Filename)
423-
actual, _ := ioutil.ReadAll(mpf)
422+
actual, _ := io.ReadAll(mpf)
424423
assert.Equal(t, content, actual)
425424
}
426425
fileverifier("file", 0, "runtime.go", cont)
@@ -432,8 +431,8 @@ func TestBuildRequest_BuildHTTP_Files(t *testing.T) {
432431
}
433432
}
434433
func TestBuildRequest_BuildHTTP_Files_URLEncoded(t *testing.T) {
435-
cont, _ := ioutil.ReadFile("./runtime.go")
436-
cont2, _ := ioutil.ReadFile("./request.go")
434+
cont, _ := os.ReadFile("./runtime.go")
435+
cont2, _ := os.ReadFile("./request.go")
437436
reqWrtr := runtime.ClientRequestWriterFunc(func(req runtime.ClientRequest, reg strfmt.Registry) error {
438437
_ = req.SetFormParam("something", "some value")
439438
_ = req.SetFileParam("file", mustGetFile("./runtime.go"))
@@ -464,7 +463,7 @@ func TestBuildRequest_BuildHTTP_Files_URLEncoded(t *testing.T) {
464463
mpf, _ := mpff.Open()
465464
defer mpf.Close()
466465
assert.Equal(t, filename, mpff.Filename)
467-
actual, _ := ioutil.ReadAll(mpf)
466+
actual, _ := io.ReadAll(mpf)
468467
assert.Equal(t, content, actual)
469468
}
470469
fileverifier("file", 0, "runtime.go", cont)
@@ -611,15 +610,15 @@ func TestGetBodyCallsBeforeRoundTrip(t *testing.T) {
611610
// Read the body once before sending the request
612611
body, err := req.GetBody()
613612
require.NoError(t, err)
614-
bodyContent, err := ioutil.ReadAll(io.Reader(body))
613+
bodyContent, err := io.ReadAll(io.Reader(body))
615614
require.EqualValues(t, req.ContentLength, len(bodyContent))
616615
require.NoError(t, err)
617616
require.EqualValues(t, "\"test body\"\n", string(bodyContent))
618617

619618
// Read the body a second time before sending the request
620619
body, err = req.GetBody()
621620
require.NoError(t, err)
622-
bodyContent, err = ioutil.ReadAll(io.Reader(body))
621+
bodyContent, err = io.ReadAll(io.Reader(body))
623622
require.NoError(t, err)
624623
require.EqualValues(t, req.ContentLength, len(bodyContent))
625624
require.EqualValues(t, "\"test body\"\n", string(bodyContent))

client/response_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package client
1616

1717
import (
1818
"bytes"
19-
"io/ioutil"
19+
"io"
2020
"net/http"
2121
"testing"
2222

@@ -31,7 +31,7 @@ func TestResponse(t *testing.T) {
3131
under.StatusCode = 392
3232
under.Header = make(http.Header)
3333
under.Header.Set("Blah", "blah blah")
34-
under.Body = ioutil.NopCloser(bytes.NewBufferString("some content"))
34+
under.Body = io.NopCloser(bytes.NewBufferString("some content"))
3535

3636
var resp runtime.ClientResponse = response{under}
3737
assert.EqualValues(t, under.StatusCode, resp.Code())

client/runtime.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import (
2323
"crypto/x509"
2424
"encoding/pem"
2525
"fmt"
26-
"io/ioutil"
2726
"mime"
2827
"net/http"
2928
"net/http/httputil"
29+
"os"
3030
"strings"
3131
"sync"
3232
"time"
@@ -164,7 +164,7 @@ func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
164164
cfg.RootCAs = caCertPool
165165
} else if opts.CA != "" {
166166
// load ca cert
167-
caCert, err := ioutil.ReadFile(opts.CA)
167+
caCert, err := os.ReadFile(opts.CA)
168168
if err != nil {
169169
return nil, fmt.Errorf("tls client ca: %v", err)
170170
}
@@ -181,8 +181,6 @@ func TLSClientAuth(opts TLSClientOptions) (*tls.Config, error) {
181181
cfg.ServerName = opts.ServerName
182182
}
183183

184-
cfg.BuildNameToCertificate()
185-
186184
return cfg, nil
187185
}
188186

client/runtime_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"encoding/json"
2020
"encoding/xml"
2121
"errors"
22-
"io/ioutil"
22+
"io"
2323
"net/http"
2424
"net/http/cookiejar"
2525
"net/http/httptest"
@@ -70,7 +70,7 @@ func TestRuntime_TLSAuthConfig(t *testing.T) {
7070
}
7171

7272
func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
73-
keyPem, err := ioutil.ReadFile("../fixtures/certs/myclient.key")
73+
keyPem, err := os.ReadFile("../fixtures/certs/myclient.key")
7474
require.NoError(t, err)
7575

7676
keyDer, _ := pem.Decode(keyPem)
@@ -79,7 +79,7 @@ func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
7979
key, err := x509.ParsePKCS1PrivateKey(keyDer.Bytes)
8080
require.NoError(t, err)
8181

82-
certPem, err := ioutil.ReadFile("../fixtures/certs/myclient.crt")
82+
certPem, err := os.ReadFile("../fixtures/certs/myclient.crt")
8383
require.NoError(t, err)
8484

8585
certDer, _ := pem.Decode(certPem)
@@ -101,7 +101,7 @@ func TestRuntime_TLSAuthConfigWithRSAKey(t *testing.T) {
101101
}
102102

103103
func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
104-
keyPem, err := ioutil.ReadFile("../fixtures/certs/myclient-ecc.key")
104+
keyPem, err := os.ReadFile("../fixtures/certs/myclient-ecc.key")
105105
require.NoError(t, err)
106106

107107
_, remainder := pem.Decode(keyPem)
@@ -111,7 +111,7 @@ func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
111111
key, err := x509.ParseECPrivateKey(keyDer.Bytes)
112112
require.NoError(t, err)
113113

114-
certPem, err := ioutil.ReadFile("../fixtures/certs/myclient-ecc.crt")
114+
certPem, err := os.ReadFile("../fixtures/certs/myclient-ecc.crt")
115115
require.NoError(t, err)
116116

117117
certDer, _ := pem.Decode(certPem)
@@ -133,7 +133,7 @@ func TestRuntime_TLSAuthConfigWithECKey(t *testing.T) {
133133
}
134134

135135
func TestRuntime_TLSAuthConfigWithLoadedCA(t *testing.T) {
136-
certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
136+
certPem, err := os.ReadFile("../fixtures/certs/myCA.crt")
137137
require.NoError(t, err)
138138

139139
block, _ := pem.Decode(certPem)
@@ -154,7 +154,7 @@ func TestRuntime_TLSAuthConfigWithLoadedCA(t *testing.T) {
154154
}
155155

156156
func TestRuntime_TLSAuthConfigWithLoadedCAPool(t *testing.T) {
157-
certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
157+
certPem, err := os.ReadFile("../fixtures/certs/myCA.crt")
158158
require.NoError(t, err)
159159

160160
block, _ := pem.Decode(certPem)
@@ -182,7 +182,7 @@ func TestRuntime_TLSAuthConfigWithLoadedCAPool(t *testing.T) {
182182
}
183183

184184
func TestRuntime_TLSAuthConfigWithLoadedCAPoolAndLoadedCA(t *testing.T) {
185-
certPem, err := ioutil.ReadFile("../fixtures/certs/myCA.crt")
185+
certPem, err := os.ReadFile("../fixtures/certs/myCA.crt")
186186
require.NoError(t, err)
187187

188188
block, _ := pem.Decode(certPem)
@@ -251,7 +251,7 @@ func TestRuntime_ManualCertificateValidation(t *testing.T) {
251251

252252
// root cert
253253
rootCertFile := "../fixtures/certs/myCA.crt"
254-
rootCertPem, err := ioutil.ReadFile(rootCertFile)
254+
rootCertPem, err := os.ReadFile(rootCertFile)
255255
require.NoError(t, err)
256256
rootCertRaw, _ := pem.Decode(rootCertPem)
257257
require.NotNil(t, rootCertRaw)
@@ -623,7 +623,7 @@ func TestRuntime_CustomTransport(t *testing.T) {
623623
buf := bytes.NewBuffer(nil)
624624
enc := json.NewEncoder(buf)
625625
_ = enc.Encode(result)
626-
resp.Body = ioutil.NopCloser(buf)
626+
resp.Body = io.NopCloser(buf)
627627
return &resp, nil
628628
})
629629

@@ -969,7 +969,7 @@ func (o *overrideRoundTripper) RoundTrip(req *http.Request) (*http.Response, err
969969
o.overriden = true
970970
res := new(http.Response)
971971
res.StatusCode = 200
972-
res.Body = ioutil.NopCloser(bytes.NewBufferString("OK"))
972+
res.Body = io.NopCloser(bytes.NewBufferString("OK"))
973973
return res, nil
974974
}
975975

client_request.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package runtime
1616

1717
import (
1818
"io"
19-
"io/ioutil"
2019
"net/http"
2120
"net/url"
2221
"time"
@@ -79,7 +78,7 @@ type NamedReadCloser interface {
7978
func NamedReader(name string, rdr io.Reader) NamedReadCloser {
8079
rc, ok := rdr.(io.ReadCloser)
8180
if !ok {
82-
rc = ioutil.NopCloser(rdr)
81+
rc = io.NopCloser(rdr)
8382
}
8483
return &namedReadCloser{
8584
name: name,

0 commit comments

Comments
 (0)