Remove ioutil usage

This has been deprecated in Go for some time, in favour of the
io package.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2023-08-22 18:29:28 +01:00
parent 55776acc0d
commit 2a88b5d2f7
8 changed files with 21 additions and 20 deletions

View File

@ -6,7 +6,7 @@ package handlers
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"math"
"net/http"
@ -27,7 +27,7 @@ func MakeAlertHandler(service scaling.ServiceQuery, defaultNamespace string) htt
defer r.Body.Close()
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("Unable to read alert."))

View File

@ -6,7 +6,7 @@ package handlers
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
@ -33,7 +33,7 @@ func Test_buildUpstreamRequest_Body_Method_Query(t *testing.T) {
t.Fail()
}
upstreamBytes, _ := ioutil.ReadAll(upstream.Body)
upstreamBytes, _ := io.ReadAll(upstream.Body)
if string(upstreamBytes) != string(srcBytes) {
t.Errorf("Body - want: %s, got: %s", string(upstreamBytes), string(srcBytes))
@ -212,7 +212,7 @@ func Test_buildUpstreamRequest_WithPathNoQuery(t *testing.T) {
t.Fail()
}
upstreamBytes, _ := ioutil.ReadAll(upstream.Body)
upstreamBytes, _ := io.ReadAll(upstream.Body)
if string(upstreamBytes) != string(srcBytes) {
t.Errorf("Body - want: %s, got: %s", string(upstreamBytes), string(srcBytes))
@ -268,7 +268,7 @@ func Test_buildUpstreamRequest_WithNoPathNoQuery(t *testing.T) {
t.Fail()
}
upstreamBytes, _ := ioutil.ReadAll(upstream.Body)
upstreamBytes, _ := io.ReadAll(upstream.Body)
if string(upstreamBytes) != string(srcBytes) {
t.Errorf("Body - want: %s, got: %s", string(upstreamBytes), string(srcBytes))
@ -322,7 +322,7 @@ func Test_buildUpstreamRequest_WithPathAndQuery(t *testing.T) {
t.Fail()
}
upstreamBytes, _ := ioutil.ReadAll(upstream.Body)
upstreamBytes, _ := io.ReadAll(upstream.Body)
if string(upstreamBytes) != string(srcBytes) {
t.Errorf("Body - want: %s, got: %s", string(upstreamBytes), string(srcBytes))

View File

@ -3,7 +3,7 @@ package handlers
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@ -52,7 +52,7 @@ func Test_logsProxyDoesNotLeakGoroutinesWhenProviderClosesConnection(t *testing.
t.Fatalf("unexpected error sending log request: %s", err)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("unexpected error reading the response body: %s", err)
}
@ -126,7 +126,7 @@ func Test_logsProxyDoesNotLeakGoroutinesWhenClientClosesConnection(t *testing.T)
go func() {
defer resp.Body.Close()
defer close(errCh)
_, err := ioutil.ReadAll(resp.Body)
_, err := io.ReadAll(resp.Body)
errCh <- err
}()
cancel()

View File

@ -5,7 +5,7 @@ package handlers
import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
@ -27,7 +27,7 @@ func MakeQueuedProxy(metrics metrics.MetricOptions, queuer ftypes.RequestQueuer,
defer r.Body.Close()
var err error
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return

View File

@ -3,7 +3,7 @@ package metrics
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httptest"
@ -28,7 +28,7 @@ func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQuery
}
defer upstreamCall.Body.Close()
upstreamBody, _ := ioutil.ReadAll(upstreamCall.Body)
upstreamBody, _ := io.ReadAll(upstreamCall.Body)
if recorder.Code != http.StatusOK {
log.Printf("List functions responded with code %d, body: %s",

View File

@ -7,7 +7,7 @@ package metrics
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
@ -159,7 +159,7 @@ func (e *Exporter) getFunctions(endpointURL url.URL, namespace string) ([]types.
return services, err
}
bytesOut, readErr := ioutil.ReadAll(res.Body)
bytesOut, readErr := io.ReadAll(res.Body)
if readErr != nil {
return services, readErr
}
@ -193,7 +193,7 @@ func (e *Exporter) getNamespaces(endpointURL url.URL) ([]string, error) {
return namespaces, nil
}
bytesOut, readErr := ioutil.ReadAll(res.Body)
bytesOut, readErr := io.ReadAll(res.Body)
if readErr != nil {
return namespaces, readErr
}

View File

@ -3,7 +3,7 @@ package metrics
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
)
@ -44,7 +44,7 @@ func (q PrometheusQuery) Fetch(query string) (*VectorQueryResponse, error) {
defer res.Body.Close()
}
bytesOut, readErr := ioutil.ReadAll(res.Body)
bytesOut, readErr := io.ReadAll(res.Body)
if readErr != nil {
return nil, readErr
}

View File

@ -3,6 +3,7 @@ package scaling
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
@ -43,7 +44,7 @@ func MakeHorizontalScalingHandler(next http.HandlerFunc) http.HandlerFunc {
return
}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, "Error reading request body", http.StatusBadRequest)
return