Skip to content

Commit

Permalink
Fix deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
svkirillov committed Aug 12, 2022
1 parent e18ad6c commit ccd9e31
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -50,7 +50,7 @@ func run(ctx context.Context, logger *logrus.Logger) error {
}

if quiet {
logger.SetOutput(ioutil.Discard)
logger.SetOutput(io.Discard)
}
logger.SetLevel(logLevel)

Expand Down
3 changes: 1 addition & 2 deletions internal/report/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
_ "embed"
"html/template"
"io"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -333,7 +332,7 @@ func exportFullReportToHtml(
return "", errors.Wrap(err, "couldn't execute template")
}

file, err := ioutil.TempFile("", "gotestwaf_report_*.html")
file, err := os.CreateTemp("", "gotestwaf_report_*.html")
if err != nil {
return "", errors.Wrap(err, "couldn't create a temporary file")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/scanner/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scanner
import (
"context"
"crypto/tls"
"io/ioutil"
"io"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -128,7 +128,7 @@ func (c *HTTPClient) SendPayload(
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return "", 0, errors.Wrap(err, "reading response body")
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *HTTPClient) SendRequest(req *http.Request, testHeaderValue string) (
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, "", 0, errors.Wrap(err, "reading response body")
}
Expand Down
3 changes: 1 addition & 2 deletions internal/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
"regexp"
Expand Down Expand Up @@ -574,7 +573,7 @@ func (s *Scanner) updateDB(
RequestValidationInput: inputReuqestValidation,
Status: respStatusCode,
Header: respHeaders,
Body: ioutil.NopCloser(strings.NewReader(respBody)),
Body: io.NopCloser(strings.NewReader(respBody)),
Options: &openapi3filter.Options{
IncludeResponseStatus: true,
},
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/waf/placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package waf
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"regexp"

Expand All @@ -28,7 +28,7 @@ func getPayloadFromHeader(r *http.Request) (string, error) {
}

func getPayloadFromHTMLForm(r *http.Request) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", fmt.Errorf("couldn't get payload from form body: %v", err)
}
Expand Down Expand Up @@ -59,15 +59,15 @@ func getPayloadFromHTMLMultipartForm(r *http.Request) (string, error) {
}

func getPayloadFromJSONBody(r *http.Request) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", fmt.Errorf("couldn't get payload from JSON body: %v", err)
}
return string(body), nil
}

func getPayloadFromJSONRequest(r *http.Request) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", fmt.Errorf("couldn't read request body: %v", err)
}
Expand All @@ -81,15 +81,15 @@ func getPayloadFromJSONRequest(r *http.Request) (string, error) {
}

func getPayloadFromRequestBody(r *http.Request) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", fmt.Errorf("couldn't get payload from request body: %v", err)
}
return string(body), nil
}

func getPayloadFromSOAPBody(r *http.Request) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", fmt.Errorf("couldn't read request body: %v", err)
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func getPayloadFromURLPath(r *http.Request) (string, error) {
}

func getPayloadFromXMLBody(r *http.Request) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", fmt.Errorf("couldn't get payload from XML body: %v", err)
}
Expand Down

0 comments on commit ccd9e31

Please sign in to comment.