Skip to content

Commit 9c3949f

Browse files
Merge pull request #103 from hainenber/replace-deprecated-ioutil-functions
chore: replace deprecated `io/ioutil` functions with modern equivalences.
2 parents 66a7893 + d688e4a commit 9c3949f

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"io/ioutil"
54
"net/url"
65
"path"
76
"strings"
@@ -118,7 +117,7 @@ func (c *Config) SetAPIToken(token string) {
118117

119118
// SetAPITokenFromFile accepts a file containing an oauth2 token for usage in http.request
120119
func (c *Config) SetAPITokenFromFile(tokenFile string) error {
121-
b, err := ioutil.ReadFile(tokenFile)
120+
b, err := os.ReadFile(tokenFile)
122121
if err != nil {
123122
return err
124123
}

exporter/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package exporter
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
neturl "net/url"
88
"strconv"
@@ -111,7 +111,7 @@ func getResponse(url string, token string, ch chan<- *Response) error {
111111
defer resp.Body.Close()
112112

113113
// Read the body to a byte array so it can be used elsewhere
114-
body, err := ioutil.ReadAll(resp.Body)
114+
body, err := io.ReadAll(resp.Body)
115115
if err != nil {
116116
return fmt.Errorf("Error converting body to byte array: %v", err)
117117
}

test/github_exporter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package test
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"os"
88
"strings"
@@ -145,7 +145,7 @@ func githubPullsError() *apitest.Mock {
145145
}
146146

147147
func readFile(path string) string {
148-
bytes, err := ioutil.ReadFile(path)
148+
bytes, err := os.ReadFile(path)
149149
if err != nil {
150150
panic(err)
151151
}
@@ -154,7 +154,7 @@ func readFile(path string) string {
154154

155155
func bodyContains(substr string) func(*http.Response, *http.Request) error {
156156
return func(res *http.Response, req *http.Request) error {
157-
bytes, err := ioutil.ReadAll(res.Body)
157+
bytes, err := io.ReadAll(res.Body)
158158
if err != nil {
159159
panic(err)
160160
}

0 commit comments

Comments
 (0)