Skip to content

Commit 0c3ee0e

Browse files
committed
migrate deprecated io/ioutil package to io and os packages
1 parent 163eee8 commit 0c3ee0e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

oapi_validate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21-
"io/ioutil"
21+
"os"
2222
"net/http"
2323
"strings"
2424

@@ -36,7 +36,7 @@ const (
3636

3737
// Create validator middleware from a YAML file path
3838
func OapiValidatorFromYamlFile(path string) (gin.HandlerFunc, error) {
39-
data, err := ioutil.ReadFile(path)
39+
data, err := os.ReadFile(path)
4040
if err != nil {
4141
return nil, fmt.Errorf("error reading %s: %s", path, err)
4242
}

oapi_validate_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
_ "embed"
2020
"errors"
2121
"fmt"
22-
"io/ioutil"
22+
"io"
2323
"net/http"
2424
"net/http/httptest"
2525
"net/url"
@@ -246,7 +246,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
246246
{
247247
rec := doGet(t, g, "http://deepmap.ai/multiparamresource?id=50")
248248
assert.Equal(t, http.StatusBadRequest, rec.Code)
249-
body, err := ioutil.ReadAll(rec.Body)
249+
body, err := io.ReadAll(rec.Body)
250250
if assert.NoError(t, err) {
251251
assert.Contains(t, string(body), "multiple errors encountered")
252252
assert.Contains(t, string(body), "parameter \\\"id2\\\"")
@@ -261,7 +261,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
261261
{
262262
rec := doGet(t, g, "http://deepmap.ai/multiparamresource")
263263
assert.Equal(t, http.StatusBadRequest, rec.Code)
264-
body, err := ioutil.ReadAll(rec.Body)
264+
body, err := io.ReadAll(rec.Body)
265265
if assert.NoError(t, err) {
266266
assert.Contains(t, string(body), "multiple errors encountered")
267267
assert.Contains(t, string(body), "parameter \\\"id\\\"")
@@ -278,7 +278,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
278278
{
279279
rec := doGet(t, g, "http://deepmap.ai/multiparamresource?id=500")
280280
assert.Equal(t, http.StatusBadRequest, rec.Code)
281-
body, err := ioutil.ReadAll(rec.Body)
281+
body, err := io.ReadAll(rec.Body)
282282
if assert.NoError(t, err) {
283283
assert.Contains(t, string(body), "multiple errors encountered")
284284
assert.Contains(t, string(body), "parameter \\\"id\\\"")
@@ -295,7 +295,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
295295
{
296296
rec := doGet(t, g, "http://deepmap.ai/multiparamresource?id=abc&id2=1")
297297
assert.Equal(t, http.StatusBadRequest, rec.Code)
298-
body, err := ioutil.ReadAll(rec.Body)
298+
body, err := io.ReadAll(rec.Body)
299299
if assert.NoError(t, err) {
300300
assert.Contains(t, string(body), "multiple errors encountered")
301301
assert.Contains(t, string(body), "parameter \\\"id\\\"")
@@ -352,7 +352,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
352352
{
353353
rec := doGet(t, g, "http://deepmap.ai/multiparamresource?id=50")
354354
assert.Equal(t, http.StatusBadRequest, rec.Code)
355-
body, err := ioutil.ReadAll(rec.Body)
355+
body, err := io.ReadAll(rec.Body)
356356
if assert.NoError(t, err) {
357357
assert.Contains(t, string(body), "Bad stuff")
358358
assert.Contains(t, string(body), "parameter \\\"id2\\\"")
@@ -367,7 +367,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
367367
{
368368
rec := doGet(t, g, "http://deepmap.ai/multiparamresource")
369369
assert.Equal(t, http.StatusBadRequest, rec.Code)
370-
body, err := ioutil.ReadAll(rec.Body)
370+
body, err := io.ReadAll(rec.Body)
371371
if assert.NoError(t, err) {
372372
assert.Contains(t, string(body), "Bad stuff")
373373
assert.Contains(t, string(body), "parameter \\\"id\\\"")
@@ -384,7 +384,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
384384
{
385385
rec := doGet(t, g, "http://deepmap.ai/multiparamresource?id=500")
386386
assert.Equal(t, http.StatusBadRequest, rec.Code)
387-
body, err := ioutil.ReadAll(rec.Body)
387+
body, err := io.ReadAll(rec.Body)
388388
if assert.NoError(t, err) {
389389
assert.Contains(t, string(body), "Bad stuff")
390390
assert.Contains(t, string(body), "parameter \\\"id\\\"")
@@ -401,7 +401,7 @@ func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T)
401401
{
402402
rec := doGet(t, g, "http://deepmap.ai/multiparamresource?id=abc&id2=1")
403403
assert.Equal(t, http.StatusBadRequest, rec.Code)
404-
body, err := ioutil.ReadAll(rec.Body)
404+
body, err := io.ReadAll(rec.Body)
405405
if assert.NoError(t, err) {
406406
assert.Contains(t, string(body), "Bad stuff")
407407
assert.Contains(t, string(body), "parameter \\\"id\\\"")

0 commit comments

Comments
 (0)