chore: remove refs to deprecated io/ioutil
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -18,11 +18,10 @@ package data
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/textproto"
|
||||
"strconv"
|
||||
"strings"
|
||||
"strings"
|
||||
|
||||
"github.com/BBVA/kapow/internal/logger"
|
||||
"github.com/BBVA/kapow/internal/server/httperror"
|
||||
@@ -183,7 +182,7 @@ func getRouteId(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
// FIXME: Allow any HTTP status code. Now we are limited by WriteHeader
|
||||
// capabilities
|
||||
func setResponseStatus(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
sb, err := ioutil.ReadAll(r.Body)
|
||||
sb, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -200,7 +199,7 @@ func setResponseStatus(w http.ResponseWriter, r *http.Request, h *model.Handler)
|
||||
|
||||
func setResponseHeaders(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
name := mux.Vars(r)["name"]
|
||||
vb, err := ioutil.ReadAll(r.Body)
|
||||
vb, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -212,7 +211,7 @@ func setResponseHeaders(w http.ResponseWriter, r *http.Request, h *model.Handler
|
||||
|
||||
func setResponseCookies(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
name := mux.Vars(r)["name"]
|
||||
vb, err := ioutil.ReadAll(r.Body)
|
||||
vb, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
@@ -242,7 +241,7 @@ func setResponseBody(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
}
|
||||
|
||||
func setServerLog(w http.ResponseWriter, r *http.Request, h *model.Handler) {
|
||||
msg, err := ioutil.ReadAll(r.Body)
|
||||
msg, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -24,11 +24,11 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -110,7 +110,7 @@ func TestGetRequestBodyWritesHandlerRequestBodyToResponseWriter(t *testing.T) {
|
||||
getRequestBody(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAR" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAR" {
|
||||
t.Error("Body mismatch")
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func TestGetRequestMethodReturnsTheCorrectMethod(t *testing.T) {
|
||||
getRequestMethod(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "FOO" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "FOO" {
|
||||
t.Error("Body mismatch")
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@ func TestGetRequestHostReturnsTheCorrectHostname(t *testing.T) {
|
||||
getRequestHost(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
||||
t.Error("Body mismatch")
|
||||
}
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func TestGetRequestVersionReturnsTheCorrectHttpVersion(t *testing.T) {
|
||||
getRequestVersion(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.Proto {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != h.Request.Proto {
|
||||
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.Proto, string(body))
|
||||
}
|
||||
}
|
||||
@@ -336,7 +336,7 @@ func TestGetRequestPathReturnsPath(t *testing.T) {
|
||||
getRequestPath(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "/foo" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "/foo" {
|
||||
t.Error("Body mismatch")
|
||||
}
|
||||
}
|
||||
@@ -352,7 +352,7 @@ func TestGetRequestPathDoesntReturnQueryStringParams(t *testing.T) {
|
||||
getRequestPath(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "/foo" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "/foo" {
|
||||
t.Errorf("Body mismatch. Expected: /foo. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -401,7 +401,7 @@ func TestGetRequestRemoteReturnsTheCorrectRemote(t *testing.T) {
|
||||
getRequestRemote(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.RemoteAddr {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != h.Request.RemoteAddr {
|
||||
t.Errorf("Version mismatch. Expected %q, got %q", h.Request.RemoteAddr, string(body))
|
||||
}
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func TestGetRequestMatchesReturnsTheCorrectMatchValue(t *testing.T) {
|
||||
getRequestMatches(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ func TestGetRequestParamsReturnsTheCorrectMatchValue(t *testing.T) {
|
||||
getRequestParams(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -553,7 +553,7 @@ func TestGetRequestParamsReturnsTheFirstCorrectMatchValue(t *testing.T) {
|
||||
getRequestParams(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -604,7 +604,7 @@ func TestGetRequestHeadersReturnsTheCorrectMatchValue(t *testing.T) {
|
||||
getRequestHeaders(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -638,7 +638,7 @@ func TestGetRequestHeadersReturnsEmptyBodyWhenHeaderIsEmptyString(t *testing.T)
|
||||
getRequestHeaders(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "" {
|
||||
t.Errorf(`Body mismatch. Expected "". Got: %q`, string(body))
|
||||
}
|
||||
}
|
||||
@@ -655,7 +655,7 @@ func TestGetRequestHeadersReturnsTheCorrectInsensitiveMatchValue(t *testing.T) {
|
||||
getRequestHeaders(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -688,7 +688,7 @@ func TestGetRequestHeadersReturnsTheFirstCorrectMatchValue(t *testing.T) {
|
||||
getRequestHeaders(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -720,7 +720,7 @@ func TestGetRequestHeadersReturnsTheCorrectValueForHostHeader(t *testing.T) {
|
||||
getRequestHeaders(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "www.foo.bar:8080" {
|
||||
t.Errorf("Body mismatch. Expected: %q. Got: %q", "www.foo.bar:8080", string(body))
|
||||
}
|
||||
}
|
||||
@@ -771,7 +771,7 @@ func TestGetRequestCookiesReturnsMatchedCookieValue(t *testing.T) {
|
||||
getRequestCookies(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -804,7 +804,7 @@ func TestGetRequestCookiesReturnsTheFirstCorrectMatchValue(t *testing.T) {
|
||||
getRequestCookies(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -869,7 +869,7 @@ func TestGetRequestFormReturnsTheCorrectMatchValue(t *testing.T) {
|
||||
getRequestForm(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf("Body mismatch. Expected: BAZ. Got: %v", string(body))
|
||||
}
|
||||
}
|
||||
@@ -925,7 +925,7 @@ func TestGetRequestFormReturnsEmptyBodyWhenFieldIsEmptyString(t *testing.T) {
|
||||
getRequestForm(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "" {
|
||||
t.Errorf(`Body mismatch. Expected: "". Got: %q`, string(body))
|
||||
}
|
||||
}
|
||||
@@ -1001,7 +1001,7 @@ func TestGetRequestFileNameReturnsTheCorrectFilename(t *testing.T) {
|
||||
getRequestFileName(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
||||
}
|
||||
}
|
||||
@@ -1080,7 +1080,7 @@ func TestGetRequestFileContentReturnsTheCorrectFileContent(t *testing.T) {
|
||||
getRequestFileContent(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
||||
}
|
||||
}
|
||||
@@ -1205,7 +1205,7 @@ func TestGetSSLClientDNSetsOctectStreamContentType(t *testing.T) {
|
||||
}
|
||||
|
||||
func mockAuthenticateClient(tls *tls.ConnectionState) error {
|
||||
fileData, err := ioutil.ReadFile("./testdata/client_chain.crt")
|
||||
fileData, err := os.ReadFile("./testdata/client_chain.crt")
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error loading certificates file: %v", err)
|
||||
}
|
||||
@@ -1237,7 +1237,7 @@ func TestGetSSLClientDNReturnsCorrectDN(t *testing.T) {
|
||||
|
||||
res := w.Result()
|
||||
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Request.TLS.VerifiedChains[0][0].Subject.String() {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != h.Request.TLS.VerifiedChains[0][0].Subject.String() {
|
||||
t.Errorf("Body mismatch. Expected: %q, got: %q", h.Request.TLS.VerifiedChains[0][0].Subject.String(), string(body))
|
||||
}
|
||||
}
|
||||
@@ -1286,7 +1286,7 @@ func TestGetRouteIdReturnsTheCorrectRouteId(t *testing.T) {
|
||||
getRouteId(w, r, &h)
|
||||
|
||||
res := w.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != h.Route.ID {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != h.Route.ID {
|
||||
t.Errorf("Body mismatch. Expected: %q, got: %q", h.Route.ID, string(body))
|
||||
}
|
||||
}
|
||||
@@ -1575,7 +1575,7 @@ func TestSetResponseBodySetsTheResponseBody(t *testing.T) {
|
||||
setResponseBody(w, r, &h)
|
||||
|
||||
res := hw.Result()
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "BAZ" {
|
||||
t.Errorf(`Body mismatch. Expected: "BAZ". Got: %q`, string(body))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package data
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -40,7 +40,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))
|
||||
|
||||
@@ -18,7 +18,7 @@ package httperror_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
@@ -53,7 +53,7 @@ func TestErrorJSONSetsBodyCorrectly(t *testing.T) {
|
||||
httperror.ErrorJSON(w, expectedReason, http.StatusNotFound)
|
||||
|
||||
errMsg := httperror.ServerErrMessage{}
|
||||
if bodyBytes, err := ioutil.ReadAll(w.Result().Body); err != nil {
|
||||
if bodyBytes, err := io.ReadAll(w.Result().Body); err != nil {
|
||||
t.Errorf("Unexpected error reading response body: %v", err)
|
||||
} else if err := json.Unmarshal(bodyBytes, &errMsg); err != nil {
|
||||
t.Errorf("Response body contains invalid JSON entity: %v", err)
|
||||
|
||||
@@ -18,7 +18,6 @@ package mux
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
@@ -152,7 +151,7 @@ func TestGorillizeReturnsAMuxThatRespectsRouteOrderAB(t *testing.T) {
|
||||
|
||||
res := w.Result()
|
||||
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "routeA" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "routeA" {
|
||||
t.Errorf("Mux did not respect route order %q", body)
|
||||
}
|
||||
}
|
||||
@@ -180,7 +179,7 @@ func TestGorillizeReturnsAMuxThatRespectsRouteOrderBA(t *testing.T) {
|
||||
|
||||
res := w.Result()
|
||||
|
||||
if body, _ := ioutil.ReadAll(res.Body); string(body) != "routeB" {
|
||||
if body, _ := io.ReadAll(res.Body); string(body) != "routeB" {
|
||||
t.Errorf("Mux did not respect route order %q", body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/BBVA/kapow/internal/logger"
|
||||
@@ -90,7 +90,7 @@ func Run(bindAddr string, wg *sync.WaitGroup, certFile, keyFile, cliCaFile strin
|
||||
func loadCertificatesFromFile(certFile string) (pool *x509.CertPool, err error) {
|
||||
if certFile != "" {
|
||||
var caCerts []byte
|
||||
caCerts, err = ioutil.ReadFile(certFile)
|
||||
caCerts, err = os.ReadFile(certFile)
|
||||
if err == nil {
|
||||
pool = x509.NewCertPool()
|
||||
if !pool.AppendCertsFromPEM(caCerts) {
|
||||
|
||||
Reference in New Issue
Block a user