From 71d6caff73582b3321ac193b3c815939e1d1766f Mon Sep 17 00:00:00 2001 From: bnkamalesh Date: Sun, 21 Apr 2024 19:24:51 +0200 Subject: [PATCH] [patch] replaced usage of deprecated package ioutil --- README.md | 2 +- config.go | 4 ++-- middleware/cors/cors_test.go | 8 ++++---- responses_test.go | 34 +++++++++++++++++----------------- router_test.go | 9 ++++----- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c9a4073..1a3c195 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![](https://godoc.org/github.com/nathany/looper?status.svg)](http://godoc.org/github.com/bnkamalesh/webgo) [![](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#web-frameworks) -# WebGo v7.0.0 +# WebGo v7.0.1 WebGo is a minimalistic router for [Go](https://golang.org) to build web applications (server side) with no 3rd party dependencies. WebGo will always be Go standard library compliant; with the HTTP handlers having the same signature as [http.HandlerFunc](https://golang.org/pkg/net/http/#HandlerFunc). diff --git a/config.go b/config.go index 82211b3..65130a1 100644 --- a/config.go +++ b/config.go @@ -2,7 +2,7 @@ package webgo import ( "encoding/json" - "io/ioutil" + "os" "strconv" "time" ) @@ -40,7 +40,7 @@ type Config struct { // Load config file from the provided filepath and validate func (cfg *Config) Load(filepath string) { - file, err := ioutil.ReadFile(filepath) + file, err := os.ReadFile(filepath) if err != nil { LOGHANDLER.Fatal(err) } diff --git a/middleware/cors/cors_test.go b/middleware/cors/cors_test.go index 9270c32..c12135e 100644 --- a/middleware/cors/cors_test.go +++ b/middleware/cors/cors_test.go @@ -11,7 +11,7 @@ package cors import ( "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "strings" @@ -43,7 +43,7 @@ func TestCORSEmptyconfig(t *testing.T) { ) router.ServeHTTP(w, req) - body, _ := ioutil.ReadAll(w.Body) + body, _ := io.ReadAll(w.Body) str := string(body) if str != "hello" { t.Errorf( @@ -93,7 +93,7 @@ func TestCORSEmptyconfig(t *testing.T) { nil, ) router.ServeHTTP(w, req) - body, _ = ioutil.ReadAll(w.Body) + body, _ = io.ReadAll(w.Body) str = string(body) if str != "" { t.Errorf( @@ -161,7 +161,7 @@ func TestCORSWithConfig(t *testing.T) { req.Header.Set("Origin", "helloworld.com") router.ServeHTTP(w, req) - body, _ := ioutil.ReadAll(w.Body) + body, _ := io.ReadAll(w.Body) str := string(body) if str != "" { t.Errorf( diff --git a/responses_test.go b/responses_test.go index afe8550..00fb208 100644 --- a/responses_test.go +++ b/responses_test.go @@ -3,7 +3,7 @@ package webgo import ( "encoding/json" "html/template" - "io/ioutil" + "io" "net/http" "net/http/httptest" "reflect" @@ -30,7 +30,7 @@ func TestSendError(t *testing.T) { Errors map[string]string }{} - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -67,7 +67,7 @@ func TestSendError(t *testing.T) { }{} invalidPayload := make(chan int) SendError(w, invalidPayload, http.StatusBadRequest) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -103,7 +103,7 @@ func TestSendResponse(t *testing.T) { payload := map[string]string{"hello": "world"} SendResponse(w, payload, http.StatusOK) - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -139,7 +139,7 @@ func TestSendResponse(t *testing.T) { // testing invalid response payload w = httptest.NewRecorder() SendResponse(w, make(chan int), http.StatusOK) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -180,7 +180,7 @@ func TestSend(t *testing.T) { reqBody, _ := json.Marshal(payload) Send(w, JSONContentType, string(reqBody), http.StatusOK) - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -228,7 +228,7 @@ func TestRender(t *testing.T) { } Render(w, data, http.StatusOK, tpl) - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -253,7 +253,7 @@ func TestRender(t *testing.T) { } Render(w, invaliddata, http.StatusOK, tpl) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -291,7 +291,7 @@ func TestResponsehelpers(t *testing.T) { R200(w, want) - body, err := ioutil.ReadAll(w.Body) + body, err := io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -324,7 +324,7 @@ func TestResponsehelpers(t *testing.T) { resp.Data = "" R201(w, want) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -357,7 +357,7 @@ func TestResponsehelpers(t *testing.T) { resp.Data = "" R204(w) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -382,7 +382,7 @@ func TestResponsehelpers(t *testing.T) { resp.Data = "" R302(w, want) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -416,7 +416,7 @@ func TestResponsehelpers(t *testing.T) { resp.Errors = "" R400(w, want) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -450,7 +450,7 @@ func TestResponsehelpers(t *testing.T) { resp.Errors = "" R403(w, want) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -484,7 +484,7 @@ func TestResponsehelpers(t *testing.T) { resp.Errors = "" R404(w, want) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -518,7 +518,7 @@ func TestResponsehelpers(t *testing.T) { resp.Errors = "" R406(w, want) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return @@ -552,7 +552,7 @@ func TestResponsehelpers(t *testing.T) { resp.Errors = "" R451(w, want) - body, err = ioutil.ReadAll(w.Body) + body, err = io.ReadAll(w.Body) if err != nil { t.Error(err.Error()) return diff --git a/router_test.go b/router_test.go index fb1ba71..7ac595c 100644 --- a/router_test.go +++ b/router_test.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "strings" @@ -233,7 +232,7 @@ func successHandler(w http.ResponseWriter, r *http.Request) { func checkPath(req *http.Request, resp *httptest.ResponseRecorder) error { want := req.URL.EscapedPath() - rbody, err := ioutil.ReadAll(resp.Body) + rbody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("error reading response, '%s'", err.Error()) } @@ -262,7 +261,7 @@ func checkPath(req *http.Request, resp *httptest.ResponseRecorder) error { func checkPathWildCard(req *http.Request, resp *httptest.ResponseRecorder) error { want := req.URL.EscapedPath() - rbody, err := ioutil.ReadAll(resp.Body) + rbody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("error reading response, '%s'", err.Error()) } @@ -301,7 +300,7 @@ func checkPathWildCard(req *http.Request, resp *httptest.ResponseRecorder) error } func checkParams(req *http.Request, resp *httptest.ResponseRecorder, keys []string, expected []string) error { - rbody, err := ioutil.ReadAll(resp.Body) + rbody, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("error reading response, '%s'", err.Error()) } @@ -681,7 +680,7 @@ func TestWildcardMadness(t *testing.T) { respRec := httptest.NewRecorder() router.ServeHTTP(respRec, req) - rbody, err := ioutil.ReadAll(respRec.Body) + rbody, err := io.ReadAll(respRec.Body) if err != nil { t.Error(err) }