refactor: move from io/ioutil to io and os package (#2236)

The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2021-10-23 17:14:12 +05:30
committed by GitHub
parent e641246866
commit 2f4ec4b2b9
40 changed files with 101 additions and 117 deletions
@@ -20,7 +20,7 @@ import (
"bytes"
"encoding/base64"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"regexp"
@@ -354,7 +354,7 @@ func invokeTriggeredFunction(conn AzureStorageConnection, sub *AzureQueueSubscri
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
if err != nil {
conn.logger.Error("failed to read response body from function invocation", zap.Error(err), zap.String("function_url", sub.functionURL))
continue
@@ -17,7 +17,7 @@ package azurequeuestorage
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
@@ -197,7 +197,7 @@ func TestAzureStorageQueuePoisonMessage(t *testing.T) {
).Return(
&http.Response{
StatusCode: http.StatusInternalServerError,
Body: ioutil.NopCloser(strings.NewReader("server error")),
Body: io.NopCloser(strings.NewReader("server error")),
},
nil,
).Once()
@@ -207,7 +207,7 @@ func TestAzureStorageQueuePoisonMessage(t *testing.T) {
).Return(
&http.Response{
StatusCode: http.StatusNotFound,
Body: ioutil.NopCloser(strings.NewReader("not found")),
Body: io.NopCloser(strings.NewReader("not found")),
},
nil,
).Once()
@@ -217,7 +217,7 @@ func TestAzureStorageQueuePoisonMessage(t *testing.T) {
).Return(
&http.Response{
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(strings.NewReader("bad request")),
Body: io.NopCloser(strings.NewReader("bad request")),
},
nil,
).Once()
@@ -227,7 +227,7 @@ func TestAzureStorageQueuePoisonMessage(t *testing.T) {
).Return(
&http.Response{
StatusCode: http.StatusForbidden,
Body: ioutil.NopCloser(strings.NewReader("not authorized")),
Body: io.NopCloser(strings.NewReader("not authorized")),
},
nil,
).Once()
@@ -339,10 +339,10 @@ func TestAzureStorageQueuePoisonMessage(t *testing.T) {
func httpRequestMatcher(t *testing.T, queue string, responseQueue string, retry string, contentType string, functionName string, body string) func(*http.Request) bool {
expectedURL := fmt.Sprintf("%s/fission-function/%s", DummyRouterURL, functionName)
return func(req *http.Request) bool {
requestBody, err := ioutil.ReadAll(req.Body)
requestBody, err := io.ReadAll(req.Body)
require.NoError(t, err)
req.Body = ioutil.NopCloser(strings.NewReader(string(requestBody)))
req.Body = io.NopCloser(strings.NewReader(string(requestBody)))
return queue == req.Header.Get("X-Fission-MQTrigger-Topic") &&
responseQueue == req.Header.Get("X-Fission-MQTrigger-RespTopic") &&
@@ -372,7 +372,7 @@ func runAzureStorageQueueTest(t *testing.T, count int, output bool) {
// Mock a HTTP client that returns http.StatusOK with "output" for the body
httpClient := new(azureHTTPClientMock)
httpClient.bodyHandler = func(res *http.Response) {
res.Body = ioutil.NopCloser(strings.NewReader(FunctionResponse))
res.Body = io.NopCloser(strings.NewReader(FunctionResponse))
}
httpClient.On(
"Do",
+3 -3
View File
@@ -20,14 +20,14 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"regexp"
"strconv"
"strings"
sarama "github.com/Shopify/sarama"
"github.com/Shopify/sarama"
cluster "github.com/bsm/sarama-cluster"
"github.com/pkg/errors"
"go.uber.org/zap"
@@ -307,7 +307,7 @@ func kafkaMsgHandler(kafka *Kafka, producer sarama.SyncProducer, trigger *fv1.Me
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
kafka.logger.Debug("got response from function invocation",
zap.String("function_url", url),
+2 -2
View File
@@ -19,7 +19,7 @@ package nats
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
@@ -192,7 +192,7 @@ func msgHandler(nats *Nats, trigger *fv1.MessageQueueTrigger) func(*ns.Msg) {
defer resp.Body.Close()
body, bodyErr := ioutil.ReadAll(resp.Body)
body, bodyErr := io.ReadAll(resp.Body)
if bodyErr != nil {
nats.logger.Error("error reading function invocation response",
zap.Error(err),