Skip to content

Commit

Permalink
Remove ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
donatj committed Jul 28, 2024
1 parent 00ac641 commit 4ec1eaf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions hmacsig.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"io/ioutil"
"io"
"net/http"
)

Expand Down Expand Up @@ -153,7 +153,7 @@ func SHA256Validator(body []byte, sig, secret string) bool {
}

func (xh *hmacSig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)

Check failure on line 156 in hmacsig.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: io.ReadAll
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -172,7 +172,7 @@ func (xh *hmacSig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

r.Body.Close()
r.Body = ioutil.NopCloser(bytes.NewBuffer(b))
r.Body = io.NopCloser(bytes.NewBuffer(b))

Check failure on line 175 in hmacsig.go

View workflow job for this annotation

GitHub Actions / test (1.14.x, ubuntu-latest)

undefined: io.NopCloser

xh.h.ServeHTTP(w, r)
}
8 changes: 4 additions & 4 deletions hmacsig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package hmacsig

import (
"bytes"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -37,7 +37,7 @@ func TestInvalidHeaders(t *testing.T) {
t.Errorf("expected status Forbidden; got %v", res.Status)
}

body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)
sbody := strings.TrimSpace(string(body))
if sbody != tc.msg {
t.Errorf("expected message '%v'; got '%v'", tc.msg, sbody)
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestValidHMAC(t *testing.T) {
rec := httptest.NewRecorder()

x := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Error(err)
}
Expand All @@ -90,7 +90,7 @@ func TestValidHMAC(t *testing.T) {
t.Errorf("expected status OK; got %v", res.Status)
}

body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)
sbody := strings.TrimSpace(string(body))
if sbody != tc.msg {
t.Errorf("expected message '%v'; got '%v'", tc.msg, sbody)
Expand Down

0 comments on commit 4ec1eaf

Please sign in to comment.