Skip to content

Commit 6520e9d

Browse files
authored
fix: use io and os instead of ioutil (#279)
use io and os instead of ioutil
1 parent 94c00c5 commit 6520e9d

15 files changed

Lines changed: 31 additions & 28 deletions

cmd/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ package cmd
44

55
import (
66
"fmt"
7-
"io/ioutil"
87
"log"
8+
"os"
99
"strings"
1010

1111
"github.com/twitchdev/twitch-cli/internal/api"
@@ -136,7 +136,7 @@ func cmdRun(cmd *cobra.Command, args []string) error {
136136
}
137137

138138
func getBodyFromFile(filename string) (string, error) {
139-
content, err := ioutil.ReadFile(filename)
139+
content, err := os.ReadFile(filename)
140140
if err != nil {
141141
return "", err
142142
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/mattn/go-sqlite3 v1.14.7
1212
github.com/spf13/cobra v1.1.3
1313
github.com/spf13/viper v1.7.1
14-
github.com/stretchr/testify v1.7.0
14+
github.com/stretchr/testify v1.8.4
1515
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
1616
)
1717

@@ -39,5 +39,5 @@ require (
3939
golang.org/x/text v0.7.0 // indirect
4040
gopkg.in/ini.v1 v1.62.0 // indirect
4141
gopkg.in/yaml.v2 v2.4.0 // indirect
42-
gopkg.in/yaml.v3 v3.0.0-20220521103104-8f96da9f5d5e // indirect
42+
gopkg.in/yaml.v3 v3.0.1 // indirect
4343
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
231231
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
232232
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
233233
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
234+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
235+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
234236
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
235237
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
236238
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -380,6 +382,8 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v
380382
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
381383
gopkg.in/yaml.v3 v3.0.0-20220521103104-8f96da9f5d5e h1:3i3ny04XV6HbZ2N1oIBw1UBYATHAOpo4tfTF83JM3Z0=
382384
gopkg.in/yaml.v3 v3.0.0-20220521103104-8f96da9f5d5e/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
385+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
386+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
383387
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
384388
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
385389
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

internal/api/api_request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package api
55
import (
66
"bytes"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"time"
1111

@@ -49,7 +49,7 @@ func apiRequest(method string, url string, payload []byte, p apiRequestParameter
4949
return apiRequestResponse{}, err
5050
}
5151

52-
body, err := ioutil.ReadAll(resp.Body)
52+
body, err := io.ReadAll(resp.Body)
5353

5454
defer resp.Body.Close()
5555

internal/api/api_request_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package api
44

55
import (
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -21,7 +21,7 @@ func TestApiRequest(t *testing.T) {
2121
a.Equal("1234", r.Header.Get("Client-ID"), "Client ID invalid.")
2222
a.Equal("Bearer 4567", r.Header.Get("Authorization"), "Token invalid.")
2323

24-
_, err := ioutil.ReadAll(r.Body)
24+
_, err := io.ReadAll(r.Body)
2525
a.Nil(err)
2626
}))
2727

internal/api/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package api
44

55
import (
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -21,7 +21,7 @@ func TestNewClient(t *testing.T) {
2121
w.WriteHeader(http.StatusOK)
2222
w.Write([]byte(ok))
2323

24-
_, err := ioutil.ReadAll(r.Body)
24+
_, err := io.ReadAll(r.Body)
2525
a.Nil(err)
2626

2727
}))
@@ -33,7 +33,7 @@ func TestNewClient(t *testing.T) {
3333
resp, err := c.Do(req)
3434
a.Nil(err)
3535

36-
body, err := ioutil.ReadAll(resp.Body)
36+
body, err := io.ReadAll(resp.Body)
3737
defer resp.Body.Close()
3838
a.NoError(err)
3939
a.Equal(ok, string(body), "Body mismatch")

internal/events/trigger/forward_event_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"crypto/hmac"
77
"crypto/sha256"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
"net/http/httptest"
1212
"testing"
@@ -29,7 +29,7 @@ func TestForwardEventEventsub(t *testing.T) {
2929
a.NotEmpty(r.Header.Get("Twitch-Eventsub-Subscription-Type"))
3030
a.NotEmpty(r.Header.Get("Twitch-Eventsub-Message-Id"))
3131

32-
body, err := ioutil.ReadAll(r.Body)
32+
body, err := io.ReadAll(r.Body)
3333
a.Nil(err)
3434
a.NotNil(body)
3535

internal/events/trigger/retrigger_event_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package trigger
44

55
import (
66
"encoding/json"
7-
"io/ioutil"
7+
"io"
88
"log"
99
"net/http"
1010
"net/http/httptest"
@@ -19,7 +19,7 @@ func TestRefireEvent(t *testing.T) {
1919
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2020
w.WriteHeader(http.StatusAccepted)
2121

22-
_, err := ioutil.ReadAll(r.Body)
22+
_, err := io.ReadAll(r.Body)
2323
a.Nil(err)
2424
}))
2525
defer ts.Close()

internal/events/trigger/trigger_event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net/rpc"
1111
"strings"
1212
"time"
@@ -202,7 +202,7 @@ https://dev.twitch.tv/docs/eventsub/handling-webhook-events#processing-an-event`
202202
}
203203
defer resp.Body.Close()
204204

205-
body, err := ioutil.ReadAll(resp.Body)
205+
body, err := io.ReadAll(resp.Body)
206206
if err != nil {
207207
return "", err
208208
}

internal/events/trigger/trigger_event_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
package trigger
44

55
import (
6-
"io/ioutil"
6+
"io"
77
"net/http"
88
"net/http/httptest"
99
"testing"
@@ -17,7 +17,7 @@ func TestFire(t *testing.T) {
1717
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1818
w.WriteHeader(http.StatusAccepted)
1919

20-
_, err := ioutil.ReadAll(r.Body)
20+
_, err := io.ReadAll(r.Body)
2121
a.Nil(err)
2222
}))
2323
defer ts.Close()

0 commit comments

Comments
 (0)