Skip to content

Commit

Permalink
chore: replace deprecated io/ioutil functions with modern equivalences
Browse files Browse the repository at this point in the history
Signed-off-by: hainenber <dotronghai96@gmail.com>
  • Loading branch information
hainenber committed Feb 28, 2024
1 parent 656e7dc commit d688e4a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"net/url"
"path"
"strings"
Expand Down Expand Up @@ -118,7 +117,7 @@ func (c *Config) SetAPIToken(token string) {

// SetAPITokenFromFile accepts a file containing an oauth2 token for usage in http.request
func (c *Config) SetAPITokenFromFile(tokenFile string) error {
b, err := ioutil.ReadFile(tokenFile)
b, err := os.ReadFile(tokenFile)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exporter

import (
"fmt"
"io/ioutil"
"io"
"net/http"
neturl "net/url"
"strconv"
Expand Down Expand Up @@ -111,7 +111,7 @@ func getResponse(url string, token string, ch chan<- *Response) error {
defer resp.Body.Close()

// Read the body to a byte array so it can be used elsewhere
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("Error converting body to byte array: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions test/github_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package test

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -145,7 +145,7 @@ func githubPullsError() *apitest.Mock {
}

func readFile(path string) string {
bytes, err := ioutil.ReadFile(path)
bytes, err := os.ReadFile(path)
if err != nil {
panic(err)
}
Expand All @@ -154,7 +154,7 @@ func readFile(path string) string {

func bodyContains(substr string) func(*http.Response, *http.Request) error {
return func(res *http.Response, req *http.Request) error {
bytes, err := ioutil.ReadAll(res.Body)
bytes, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit d688e4a

Please sign in to comment.