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
@@ -18,7 +18,7 @@ package control
import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"github.com/google/uuid"
@@ -103,7 +103,7 @@ var pathValidator func(string) error = func(path string) error {
func addRoute(res http.ResponseWriter, req *http.Request) {
var route model.Route
payload, _ := ioutil.ReadAll(req.Body)
payload, _ := io.ReadAll(req.Body)
err := json.Unmarshal(payload, &route)
if err != nil {
httperror.ErrorJSON(res, "Malformed JSON", http.StatusBadRequest)
+3 -3
View File
@@ -20,7 +20,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"reflect"
@@ -47,7 +47,7 @@ func checkErrorResponse(r *http.Response, expectedErrcode int, expectedReason st
}
errMsg := httperror.ServerErrMessage{}
if bodyBytes, err := ioutil.ReadAll(r.Body); err != nil {
if bodyBytes, err := io.ReadAll(r.Body); err != nil {
errList = append(errList, fmt.Errorf("Unexpected error reading response body: %v", err))
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
errList = append(errList, fmt.Errorf("Response body contains invalid JSON entity: %v", err))
@@ -434,7 +434,7 @@ func TestGetRouteReturnsTheRequestedRoute(t *testing.T) {
t.Errorf("HTTP status mismatch. Expected: %d, got: %d", http.StatusOK, resp.StatusCode)
}
bBytes, _ := ioutil.ReadAll(resp.Body)
bBytes, _ := io.ReadAll(resp.Body)
if err := json.Unmarshal(bBytes, &respJson); err != nil {
t.Errorf("Invalid JSON response. %s", string(bBytes))
}