Skip to content

Commit

Permalink
remove deprecated io/ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Aug 15, 2022
1 parent 79ac1df commit 3e58b63
Show file tree
Hide file tree
Showing 26 changed files with 66 additions and 80 deletions.
4 changes: 2 additions & 2 deletions bundle/client/coap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -110,7 +110,7 @@ func decodePayload(resp *pool.Message) {
"Payload: ",
)
if err == nil {
bufr, err := ioutil.ReadAll(resp.Body())
bufr, err := io.ReadAll(resp.Body())
if err != nil {
buf += fmt.Sprintf("cannot read body: %v", err)
log.Print(buf)
Expand Down
5 changes: 2 additions & 3 deletions bundle/client/grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"

Expand Down Expand Up @@ -102,7 +101,7 @@ func updateResource(ctx context.Context, client pbGW.GrpcGatewayClient, deviceID
updError := func(err error) {
log.Fatalf("cannot update resource: %v", err)
}
data, err := ioutil.ReadAll(os.Stdin)
data, err := io.ReadAll(os.Stdin)
if err != nil {
updError(fmt.Errorf("cannot read data: %w", err))
}
Expand All @@ -127,7 +126,7 @@ func createResource(ctx context.Context, client pbGW.GrpcGatewayClient, deviceID
createError := func(err error) {
log.Fatalf("cannot create resource: %v", err)
}
data, err := ioutil.ReadAll(os.Stdin)
data, err := io.ReadAll(os.Stdin)
if err != nil {
createError(fmt.Errorf("cannot read data: %w", err))
}
Expand Down
3 changes: 1 addition & 2 deletions cloud2cloud-connector/service/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
"sync"
Expand Down Expand Up @@ -97,7 +96,7 @@ func Get(ctx context.Context, tracerProvider trace.TracerProvider, url string, l
log.Errorf("failed to close response body: %w", err)
}
}()
buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cloud2cloud-connector/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"crypto/tls"
"encoding/pem"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -114,7 +114,7 @@ func SetUpClouds(ctx context.Context, t *testing.T, deviceID string, supportedEv
defer func(r *http.Response) {
_ = r.Body.Close()
}(resp)
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
require.NoError(t, err)
fmt.Println(string(b))

Expand Down
3 changes: 1 addition & 2 deletions cloud2cloud-gateway/service/emitEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
netHttp "net/http"
"strconv"
"time"
Expand Down Expand Up @@ -127,7 +126,7 @@ func createEmitEventFunc(cfg cmClient.Config, timeout time.Duration, fileWatcher
}
}()
if resp.StatusCode != netHttp.StatusOK {
errBody, _ := ioutil.ReadAll(resp.Body)
errBody, _ := io.ReadAll(resp.Body)
return resp.StatusCode == netHttp.StatusGone, fmt.Errorf("%v: unexpected statusCode %v: body: '%v'", s.URL, resp.StatusCode, string(errBody))
}
return eventType == events.EventType_SubscriptionCanceled, nil
Expand Down
10 changes: 5 additions & 5 deletions cloud2cloud-gateway/service/subscribeToDevices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestRequestHandlerSubscribeToDevices(t *testing.T) {
_ = r.Body.Close()
}()
assert.Equal(t, wantEventType, h.EventType)
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
assert.NoError(t, err)
var v interface{}
err = json.Decode(buf, &v)
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestRequestHandlerSubscribeToDevices(t *testing.T) {
defer func() {
_ = resp.Body.Close()
}()
v, err := ioutil.ReadAll(resp.Body)
v, err := io.ReadAll(resp.Body)
fmt.Printf("body %v\n", string(v))
require.NoError(t, err)
require.Equal(t, wantContentType, resp.Header.Get("Content-Type"))
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestRequestHandlerSubscribeToDevicesOffline(t *testing.T) {
_ = r.Body.Close()
}()
assert.Equal(t, wantEventType, h.EventType)
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
assert.NoError(t, err)
var v interface{}
err = json.Decode(buf, &v)
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestRequestHandlerSubscribeToDevicesOffline(t *testing.T) {
defer func() {
_ = resp.Body.Close()
}()
v, err := ioutil.ReadAll(resp.Body)
v, err := io.ReadAll(resp.Body)
fmt.Printf("body %v\n", string(v))
require.NoError(t, err)
require.Equal(t, wantContentType, resp.Header.Get("Content-Type"))
Expand Down
4 changes: 2 additions & 2 deletions cloud2cloud-gateway/test/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package test

import (
"crypto/tls"
"io/ioutil"
"io"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -138,7 +138,7 @@ func (s *EventsServer) Run(t *testing.T) EventChan {
defer func() {
_ = r.Body.Close()
}()
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
assert.NoError(t, err)

data := DecodeEvent(t, h.EventType, buf)
Expand Down
6 changes: 3 additions & 3 deletions cloud2cloud-gateway/test/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package test
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -72,7 +72,7 @@ func (c *C2CSubscriber) Subscribe(t *testing.T, ctx context.Context, token, devi
defer func() {
_ = resp.Body.Close()
}()
respData, err := ioutil.ReadAll(resp.Body)
respData, err := io.ReadAll(resp.Body)
require.NoError(t, err)
fmt.Printf("body %v\n", string(respData))
require.Equal(t, message.AppJSON.String(), resp.Header.Get("Content-Type"))
Expand Down Expand Up @@ -113,6 +113,6 @@ func (c *C2CSubscriber) Unsubscribe(t *testing.T, ctx context.Context, token, de
defer func() {
_ = resp.Body.Close()
}()
_, err := ioutil.ReadAll(resp.Body)
_, err := io.ReadAll(resp.Body)
require.NoError(t, err)
}
3 changes: 1 addition & 2 deletions coap-gateway/coapconv/coapconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"strings"

"github.com/google/uuid"
Expand Down Expand Up @@ -157,7 +156,7 @@ func GetContentData(opts message.Options, body io.Reader) (data []byte, contentF
contentFormat = int32(mt)
}
if body != nil {
data, _ = ioutil.ReadAll(body)
data, _ = io.ReadAll(body)
}
return data, contentFormat
}
Expand Down
4 changes: 2 additions & 2 deletions coap-gateway/service/clientDeleteHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package service_test

import (
"context"
"io/ioutil"
"io"
"testing"
"time"

Expand Down Expand Up @@ -80,7 +80,7 @@ func TestClientDeleteHandler(t *testing.T) {
assert.Equal(t, tt.wantsCode.String(), resp.Code().String())
if tt.wantsContent != nil {
require.NotEmpty(t, resp.Body())
b, err := ioutil.ReadAll(resp.Body())
b, err := io.ReadAll(resp.Body())
require.NoError(t, err)
assert.Equal(t, tt.wantsContent, b)
}
Expand Down
3 changes: 1 addition & 2 deletions coap-gateway/service/message/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package message

import (
"io"
"io/ioutil"

"github.com/plgd-dev/go-coap/v2/message"
"github.com/plgd-dev/go-coap/v2/tcp/message/pool"
Expand Down Expand Up @@ -36,7 +35,7 @@ func readBody(r io.ReadSeeker) []byte {
if err != nil {
return nil
}
body, err := ioutil.ReadAll(r)
body, err := io.ReadAll(r)
if err != nil {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions coap-gateway/service/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"encoding/pem"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"reflect"
"testing"
Expand Down Expand Up @@ -61,7 +61,7 @@ func testValidateResp(t *testing.T, test testEl, resp *pool.Message) {
if bodySize == 0 && test.out.payload == nil {
return
}
body, err := ioutil.ReadAll(resp.Body())
body, err := io.ReadAll(resp.Body())
require.NoError(t, err)
if contentType, err := resp.ContentFormat(); err == nil {
switch contentType {
Expand Down
3 changes: 1 addition & 2 deletions grpc-gateway/client/generalMessageCodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"fmt"
"io"
"io/ioutil"

"github.com/plgd-dev/go-coap/v2/message"
"github.com/plgd-dev/kit/v2/codec/cbor"
Expand Down Expand Up @@ -38,7 +37,7 @@ func (GeneralMessageCodec) Decode(m *message.Message, v interface{}) error {
decoder = json.ReadFrom
case message.TextPlain:
decoder = func(w io.Reader, v interface{}) error {
data, err := ioutil.ReadAll(w)
data, err := io.ReadAll(w)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions http-gateway/service/getWebConfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"os"
"testing"
Expand Down Expand Up @@ -126,7 +125,7 @@ func TestRequestHandlerGetWebDirectory(t *testing.T) {
got, err := io.ReadAll(resp.Body)
require.NoError(t, err)

want, err := ioutil.ReadFile(tt.wantFile)
want, err := os.ReadFile(tt.wantFile)
require.NoError(t, err)

require.Equal(t, got, want)
Expand Down
5 changes: 2 additions & 3 deletions http-gateway/service/updateResource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"

"github.com/gorilla/mux"
Expand All @@ -18,7 +17,7 @@ import (
)

func createContentBody(body io.ReadCloser) (io.ReadCloser, error) {
data, err := ioutil.ReadAll(body)
data, err := io.ReadAll(body)
if err != nil {
return nil, fmt.Errorf("read body: %w", err)
}
Expand All @@ -33,7 +32,7 @@ func createContentBody(body io.ReadCloser) (io.ReadCloser, error) {
return nil, fmt.Errorf("cannot marshal to protojson: %w", err)
}

return ioutil.NopCloser(bytes.NewReader(reqData)), nil
return io.NopCloser(bytes.NewReader(reqData)), nil
}

func (requestHandler *RequestHandler) updateResource(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

import (
"fmt"
"io/ioutil"
"os"

"github.com/jessevdk/go-flags"
)
Expand Down Expand Up @@ -40,7 +40,7 @@ func Load(config interface{}) error {

// Read reads config from file.
func Read(filename string, config interface{}) error {
cfg, err := ioutil.ReadFile(filename)
cfg, err := os.ReadFile(filename)
if err != nil {
return err
}
Expand Down
15 changes: 7 additions & 8 deletions pkg/security/certManager/client/certManager_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client_test

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -48,23 +47,23 @@ AnQ1eTGKTGLdAZsV+NnZPL17nit1cbiN2g==

func TestNew(t *testing.T) {
// tmp dir
tmpDir, err := ioutil.TempDir("/tmp", "test")
tmpDir, err := os.MkdirTemp("/tmp", "test")
require.NoError(t, err)
defer func() {
_ = deleteTmpDir(tmpDir)
}()
// ca
caFile, err := ioutil.TempFile(tmpDir, "ca")
caFile, err := os.CreateTemp(tmpDir, "ca")
require.NoError(t, err)
err = caFile.Close()
require.NoError(t, err)

crtFile, err := ioutil.TempFile(tmpDir, "crt")
crtFile, err := os.CreateTemp(tmpDir, "crt")
require.NoError(t, err)
err = crtFile.Close()
require.NoError(t, err)

keyFile, err := ioutil.TempFile(tmpDir, "key")
keyFile, err := os.CreateTemp(tmpDir, "key")
require.NoError(t, err)
err = keyFile.Close()
require.NoError(t, err)
Expand Down Expand Up @@ -104,15 +103,15 @@ func TestNew(t *testing.T) {

func createTmpCertFiles(t *testing.T, caFile, crtFile, keyFile string) client.Config {
// ca
err := ioutil.WriteFile(caFile, []byte(TestCaCrt), os.FileMode(os.O_RDWR))
err := os.WriteFile(caFile, []byte(TestCaCrt), os.FileMode(os.O_RDWR))
require.NoError(t, err)

// crt
err = ioutil.WriteFile(crtFile, []byte(TestCrt), os.FileMode(os.O_RDWR))
err = os.WriteFile(crtFile, []byte(TestCrt), os.FileMode(os.O_RDWR))
require.NoError(t, err)

// key
err = ioutil.WriteFile(keyFile, []byte(TestCrtKey), os.FileMode(os.O_RDWR))
err = os.WriteFile(keyFile, []byte(TestCrtKey), os.FileMode(os.O_RDWR))
require.NoError(t, err)

cfg := client.Config{
Expand Down
Loading

0 comments on commit 3e58b63

Please sign in to comment.