Skip to content

Commit

Permalink
chore: Drop deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: shuheiktgw <shuheiktgw@users.noreply.github.com>
  • Loading branch information
shuheiktgw committed Jul 30, 2021
1 parent df459c5 commit 38d3ca1
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 42 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/scheduler_daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestScheduler_DaemonSetTargetPortName(t *testing.T) {

func TestScheduler_DaemonSetAlerts(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var payload = notifier.SlackPayload{}
err = json.Unmarshal(b, &payload)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/scheduler_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestScheduler_DeploymentTargetPortName(t *testing.T) {

func TestScheduler_DeploymentAlerts(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var payload = notifier.SlackPayload{}
err = json.Unmarshal(b, &payload)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -67,7 +67,7 @@ func callWebhook(webhook string, payload interface{}, timeout string) error {
}
defer r.Body.Close()

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return fmt.Errorf("error reading body: %s", err.Error())
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/loadtester/concord.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
Expand Down Expand Up @@ -189,7 +188,7 @@ func (task *ConcordTask) newRequest(method, path string, contentType string, bod
}

apiKey := ""
dat, err := ioutil.ReadFile(task.APIKeyPath)
dat, err := os.ReadFile(task.APIKeyPath)
if err != nil {
return req, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/loadtester/concord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package loadtester
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"mime/multipart"
"testing"

Expand Down Expand Up @@ -94,7 +94,7 @@ func assertNextPartHasKeyAndValue(t *testing.T, r *multipart.Reader, key string,
}
// assert.Equal(t, 1, part)

slurp, err := ioutil.ReadAll(part)
slurp, err := io.ReadAll(part)
if err != nil {
fmt.Printf("Part: %+v", part)
t.Fatalf("Couldn't read part: %v", err)
Expand Down
16 changes: 8 additions & 8 deletions pkg/loadtester/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
Expand All @@ -44,7 +44,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
w.Write([]byte("Forbidden"))
})
mux.HandleFunc("/gate/check", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("reading the request body failed", zap.Error(err))
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -74,7 +74,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
})

mux.HandleFunc("/gate/open", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("reading the request body failed", zap.Error(err))
w.WriteHeader(http.StatusBadRequest)
Expand All @@ -99,7 +99,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
})

mux.HandleFunc("/gate/close", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("reading the request body failed", zap.Error(err))
w.WriteHeader(http.StatusBadRequest)
Expand All @@ -124,7 +124,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
})

mux.HandleFunc("/rollback/check", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("reading the request body failed", zap.Error(err))
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -153,7 +153,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
logger.Infof("%s rollback check: approved %v", canaryName, approved)
})
mux.HandleFunc("/rollback/open", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("reading the request body failed", zap.Error(err))
w.WriteHeader(http.StatusBadRequest)
Expand All @@ -177,7 +177,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
logger.Infof("%s rollback opened", canaryName)
})
mux.HandleFunc("/rollback/close", func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("reading the request body failed", zap.Error(err))
w.WriteHeader(http.StatusBadRequest)
Expand Down Expand Up @@ -235,7 +235,7 @@ func HandleHealthz(w http.ResponseWriter, r *http.Request) {
// HandleNewTask handles task creation requests
func HandleNewTask(logger *zap.SugaredLogger, taskRunner TaskRunnerInterface) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Error("reading the request body failed", zap.Error(err))
w.WriteHeader(http.StatusBadRequest)
Expand Down
4 changes: 2 additions & 2 deletions pkg/loadtester/task_ngrinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -167,7 +167,7 @@ func (task *NGrinderTask) request(method, url string, ctx context.Context) (map[
}
defer resp.Body.Close()

respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("reading response body failed: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/metrics/providers/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -125,7 +125,7 @@ func (p *DatadogProvider) RunQuery(query string) (float64, error) {
}

defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return 0, fmt.Errorf("error reading body: %w", err)
}
Expand Down Expand Up @@ -176,7 +176,7 @@ func (p *DatadogProvider) IsOnline() (bool, error) {

defer r.Body.Close()

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return false, fmt.Errorf("error reading body: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/providers/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"math"
"net/http"
"net/url"
Expand Down Expand Up @@ -183,7 +183,7 @@ func (g *GraphiteProvider) RunQuery(query string) (float64, error) {
}
defer r.Body.Close()

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return 0, fmt.Errorf("error reading body: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/metrics/providers/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"time"

Expand Down Expand Up @@ -105,7 +105,7 @@ func (p *NewRelicProvider) RunQuery(query string) (float64, error) {
}

defer r.Body.Close()
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return 0, fmt.Errorf("error reading body: %w", err)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (p *NewRelicProvider) IsOnline() (bool, error) {

defer r.Body.Close()

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return false, fmt.Errorf("error reading body: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/providers/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -121,7 +121,7 @@ func (p *PrometheusProvider) RunQuery(query string) (float64, error) {
}
defer r.Body.Close()

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return 0, fmt.Errorf("error reading body: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/notifier/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -75,7 +75,7 @@ func postMessage(address string, proxy string, payload interface{}) error {
defer res.Body.Close()
statusCode := res.StatusCode
if statusCode != 200 {
body, _ := ioutil.ReadAll(res.Body)
body, _ := io.ReadAll(res.Body)
return fmt.Errorf("sending notification failed: %s", string(body))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/notifier/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package notifier

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -28,7 +28,7 @@ import (

func Test_postMessage(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)

var payload = make(map[string]string)
Expand Down
4 changes: 2 additions & 2 deletions pkg/notifier/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package notifier

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand All @@ -35,7 +35,7 @@ func TestDiscord_Post(t *testing.T) {
}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var payload = SlackPayload{}
err = json.Unmarshal(b, &payload)
Expand Down
4 changes: 2 additions & 2 deletions pkg/notifier/rocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package notifier

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -33,7 +33,7 @@ func TestRocket_Post(t *testing.T) {
}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)

var payload = SlackPayload{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/notifier/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package notifier

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -33,7 +33,7 @@ func TestSlack_Post(t *testing.T) {
}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)

var payload = SlackPayload{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/notifier/teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package notifier

import (
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -34,7 +34,7 @@ func TestTeams_Post(t *testing.T) {
}

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
require.NoError(t, err)
var payload = MSTeamsPayload{}
err = json.Unmarshal(b, &payload)
Expand Down

0 comments on commit 38d3ca1

Please # to comment.