Skip to content

Commit

Permalink
chore: Drop deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: Ali AKCA <ali@akca.io>
  • Loading branch information
aweris committed Oct 27, 2021
1 parent 849126e commit 7ded18f
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions internal/notifier/alertmanger_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 TestAlertmanager_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 []AlertManagerAlert
err = json.Unmarshal(b, &payload)
Expand Down
4 changes: 2 additions & 2 deletions internal/notifier/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -94,7 +94,7 @@ func postMessage(address, proxy string, certPool *x509.CertPool, payload interfa
}

if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusCreated {
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("unable to read response body, %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/notifier/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package notifier
import (
"crypto/x509"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -33,7 +33,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 All @@ -49,7 +49,7 @@ func Test_postMessage(t *testing.T) {

func Test_postSelfSignedCert(t *testing.T) {
ts := httptest.NewTLSServer(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 internal/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 @@ -30,7 +30,7 @@ import (

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{}
Expand Down
4 changes: 2 additions & 2 deletions internal/notifier/forwarder_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 @@ -30,7 +30,7 @@ import (

func TestForwarder_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)

require.Equal(t, "source-controller", r.Header.Get("gotk-component"))
Expand Down
4 changes: 2 additions & 2 deletions internal/notifier/google_chat_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 TestGoogleChat_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 = GoogleChatPayload{}
err = json.Unmarshal(b, &payload)
Expand Down
4 changes: 2 additions & 2 deletions internal/notifier/lark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package notifier

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

func TestLark_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 LarkPayload
err = json.Unmarshal(b, &payload)
Expand Down
4 changes: 2 additions & 2 deletions internal/notifier/opsgenie_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 TestOpsgenie_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 OpsgenieAlert
err = json.Unmarshal(b, &payload)
Expand Down
4 changes: 2 additions & 2 deletions internal/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 @@ -28,7 +28,7 @@ import (

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 internal/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 @@ -28,7 +28,7 @@ import (

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 internal/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 @@ -28,7 +28,7 @@ import (

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
4 changes: 2 additions & 2 deletions internal/notifier/webex_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 TestWebex_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 = WebexPayload{}
Expand Down
4 changes: 2 additions & 2 deletions internal/server/event_handlers.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"
"regexp"
"time"
Expand All @@ -40,7 +40,7 @@ import (

func (s *EventServer) handleEvent() 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 {
s.logger.Error(err, "reading the request body failed")
w.WriteHeader(http.StatusBadRequest)
Expand Down
10 changes: 5 additions & 5 deletions internal/server/event_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -107,7 +107,7 @@ func (s *EventServer) logRateLimitMiddleware(h http.Handler) http.Handler {
h.ServeHTTP(recorder, r)

if recorder.Status == http.StatusTooManyRequests {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
s.logger.Error(err, "reading the request body failed")
w.WriteHeader(http.StatusBadRequest)
Expand All @@ -122,7 +122,7 @@ func (s *EventServer) logRateLimitMiddleware(h http.Handler) http.Handler {
return
}

r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))

s.logger.V(1).Info("Discarding event, rate limiting duplicate events",
"reconciler kind", event.InvolvedObject.Kind,
Expand All @@ -133,7 +133,7 @@ func (s *EventServer) logRateLimitMiddleware(h http.Handler) http.Handler {
}

func eventKeyFunc(r *http.Request) (string, error) {
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return "", err
}
Expand All @@ -144,7 +144,7 @@ func eventKeyFunc(r *http.Request) (string, error) {
return "", err
}

r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
r.Body = io.NopCloser(bytes.NewBuffer(body))

comps := []string{"event", event.InvolvedObject.Name, event.InvolvedObject.Namespace, event.InvolvedObject.Kind, event.Message}
revString, ok := event.Metadata["revision"]
Expand Down
6 changes: 3 additions & 3 deletions internal/server/receiver_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver v1beta1.Receiver
case v1beta1.GenericReceiver:
return nil
case v1beta1.GenericHMACReceiver:
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return fmt.Errorf("unable to read request body: %s", err)
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func (s *ReceiverServer) validate(ctx context.Context, receiver v1beta1.Receiver
return fmt.Errorf("Nexus signature is missing from header")
}

b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
return fmt.Errorf("cannot read Nexus payload. error: %s", err)
}
Expand Down

0 comments on commit 7ded18f

Please sign in to comment.