chore: remove refs to deprecated io/ioutil

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
guoguangwu
2023-10-19 11:05:38 +08:00
parent 958b0671bd
commit 115e48a202
12 changed files with 56 additions and 59 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ package http
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"github.com/BBVA/kapow/internal/server/httperror"
@@ -28,7 +28,7 @@ import (
// Reason returns the reason phrase embedded within the JSON error
// body, or an error if no reason can be extracted
func Reason(r *http.Response) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", errors.New("error reading response's body")
}
+6 -6
View File
@@ -17,7 +17,7 @@
package http
import (
"io/ioutil"
"io"
nethttp "net/http"
"strings"
"testing"
@@ -26,7 +26,7 @@ import (
func TestReasonExtractsReasonFromJSON(t *testing.T) {
r := &nethttp.Response{
Status: "200 OK",
Body: ioutil.NopCloser(
Body: io.NopCloser(
strings.NewReader(
`{"reason": "Because reasons", "foo": "bar"}`,
),
@@ -43,7 +43,7 @@ func TestReasonExtractsReasonFromJSON(t *testing.T) {
func TestReasonErrorsOnJSONWithNoReason(t *testing.T) {
r := &nethttp.Response{
Status: "200 OK",
Body: ioutil.NopCloser(
Body: io.NopCloser(
strings.NewReader(
`{"madness": "Because madness", "foo": "bar"}`,
),
@@ -59,7 +59,7 @@ func TestReasonErrorsOnJSONWithNoReason(t *testing.T) {
func TestReasonErrorsOnJSONWithEmptyReason(t *testing.T) {
r := &nethttp.Response{
Body: ioutil.NopCloser(
Body: io.NopCloser(
strings.NewReader(
`{"reason": "", "foo": "bar"}`,
),
@@ -75,7 +75,7 @@ func TestReasonErrorsOnJSONWithEmptyReason(t *testing.T) {
func TestReasonErrorsOnNoJSON(t *testing.T) {
r := &nethttp.Response{
Body: ioutil.NopCloser(
Body: io.NopCloser(
strings.NewReader(""),
),
}
@@ -89,7 +89,7 @@ func TestReasonErrorsOnNoJSON(t *testing.T) {
func TestReasonErrorsOnInvalidJSON(t *testing.T) {
r := &nethttp.Response{
Body: ioutil.NopCloser(
Body: io.NopCloser(
strings.NewReader(
`{"reason": "Because reasons", "cliffhanger...`,
),
+1 -2
View File
@@ -21,7 +21,6 @@ import (
"crypto/x509"
"errors"
"io"
"io/ioutil"
"net/http"
"os"
@@ -54,7 +53,7 @@ func Delete(url string, r io.Reader, w io.Writer, clientGenerator func() *http.C
return Request("DELETE", url, r, w, clientGenerator, reqTuner...)
}
var devnull = ioutil.Discard
var devnull = io.Discard
// Request will perform the request to the given url and method sending the
// content of the given reader as the body and writing all the contents