Skip to content

Commit

Permalink
replace deprecated ioutil APIs (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhodges authored Nov 19, 2024
1 parent 23e2e39 commit 2303dd5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -100,7 +100,7 @@ func callAutograph(auth authorization, body []byte, xff string) (signedBody []by
return
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return
}
Expand Down
12 changes: 6 additions & 6 deletions handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -39,7 +39,7 @@ func Test_heartbeatHandler(t *testing.T) {
upstreamResponse: &http.Response{
Status: http.StatusText(http.StatusOK),
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
},
upstreamErr: nil,
expectedResponse: expectedResponse{
Expand All @@ -57,7 +57,7 @@ func Test_heartbeatHandler(t *testing.T) {
upstreamResponse: &http.Response{
Status: http.StatusText(http.StatusBadGateway),
StatusCode: http.StatusBadGateway,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
},
upstreamErr: nil,
expectedResponse: expectedResponse{
Expand Down Expand Up @@ -100,7 +100,7 @@ func Test_heartbeatHandler(t *testing.T) {
heartbeatHandler(tt.args.baseURL, client)(w, tt.args.r)

resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)

if resp.StatusCode != tt.expectedResponse.status {
t.Fatalf("heartbeatHandler() returned unexpected status %v expected %v", resp.StatusCode, tt.expectedResponse.status)
Expand All @@ -122,7 +122,7 @@ func TestVersion(t *testing.T) {
versionHandler(w, req)

resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)

if resp.StatusCode != http.StatusOK {
t.Fatalf("returned unexpected status %v expected %v", resp.StatusCode, http.StatusOK)
Expand All @@ -141,7 +141,7 @@ func TestNotFoundHandler(t *testing.T) {
notFoundHandler(w, req)

resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)

if resp.StatusCode != http.StatusNotFound {
t.Fatalf("returned unexpected status %v expected %v", resp.StatusCode, http.StatusOK)
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -153,7 +153,7 @@ func prepareServer(host string, port int) *http.Server {
// loadFromFile reads a configuration from a local file
func (c *configuration) loadFromFile(path string) error {
var confData []byte
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func httpError(w http.ResponseWriter, r *http.Request, errorCode int, errorMessa
// request body is read before writing a response.
// https://github.com/golang/go/issues/15789
if r.Body != nil {
io.Copy(ioutil.Discard, r.Body)
io.Copy(io.Discard, r.Body)
r.Body.Close()
}
http.Error(w, msg, errorCode)
Expand Down
3 changes: 1 addition & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -567,7 +566,7 @@ Content-Type: application/octet-stream
req, err := http.NewRequest(
tt.method,
fmt.Sprintf(testServer.URL+tt.path),
ioutil.NopCloser(bytes.NewReader(tt.body)),
io.NopCloser(bytes.NewReader(tt.body)),
)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 2303dd5

Please sign in to comment.