Skip to content

Commit

Permalink
[patch] replaced usage of deprecated package ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
bnkamalesh committed Apr 21, 2024
1 parent 48529df commit 71d6caf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package webgo

import (
"encoding/json"
"io/ioutil"
"os"
"strconv"
"time"
)
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions middleware/cors/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package cors

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
34 changes: 17 additions & 17 deletions responses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package webgo
import (
"encoding/json"
"html/template"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"reflect"
Expand All @@ -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)

Check failure on line 33 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -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)

Check failure on line 70 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -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)

Check failure on line 106 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -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)

Check failure on line 142 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -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)

Check failure on line 183 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -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)

Check failure on line 231 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand All @@ -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)

Check failure on line 256 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestResponsehelpers(t *testing.T) {

R200(w, want)

body, err := ioutil.ReadAll(w.Body)
body, err := io.ReadAll(w.Body)

Check failure on line 294 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -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)

Check failure on line 327 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

undefined: io.ReadAll

Check failure on line 327 in responses_test.go

View workflow job for this annotation

GitHub Actions / Test with Go 1.13

too many errors
if err != nil {
t.Error(err.Error())
return
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 71d6caf

Please sign in to comment.