Skip to content

Commit

Permalink
Cleanup deprecated api usage (ioutil -> io and os)
Browse files Browse the repository at this point in the history
  • Loading branch information
gesellix committed Sep 19, 2022
1 parent 901a237 commit c4ee43c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions couchdb-exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"encoding/base64"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"net/http/httptest"
"net/url"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -61,7 +61,7 @@ func BasicAuthHandler(basicAuth lib.BasicAuth, pass Handler) Handler {
}

func readFile(t *testing.T, filename string) []byte {
fileContent, err := ioutil.ReadFile(filename)
fileContent, err := os.ReadFile(filename)
if err != nil {
t.Errorf("Error reading file %s: %v\n", filename, err)
}
Expand Down
10 changes: 5 additions & 5 deletions fileutil/properties_file_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -109,21 +109,21 @@ func loadDataFrom(filePath string) ([]byte, error) {
if err != nil {
return nil, err
}
return ioutil.ReadAll(res.Body)
return io.ReadAll(res.Body)
default:
return nil, fmt.Errorf("scheme of %s is unsupported", filePath)
}
} else if u.Path != "" { // i dont have a host, but I have a path. I am a local file.
} else if u.Path != "" { // I don't have a host, but I have a path. I am a local file.
if _, notFoundFileErr := os.Stat(filePath); notFoundFileErr != nil {
return nil, fmt.Errorf("cannot read from file: '%s' because it does not exist", filePath)
}
return ioutil.ReadFile(filePath)
return os.ReadFile(filePath)
} else if runtime.GOOS == "windows" && strings.Contains(u.String(), "\\") {
// on Windows systems u.Path is always empty, so we need to check the string directly.
if _, notFoundFileErr := os.Stat(filePath); notFoundFileErr != nil {
return nil, fmt.Errorf("cannot read from file: '%s' because it does not exist", filePath)
}
return ioutil.ReadFile(filePath)
return os.ReadFile(filePath)
} else {
return nil, fmt.Errorf("unable to determine how to load from path %s", filePath)
}
Expand Down
3 changes: 1 addition & 2 deletions lib/couchdb-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -575,7 +574,7 @@ func (c *CouchdbClient) Request(method string, uri string, body io.Reader) (resp
}()
}

respData, err = ioutil.ReadAll(resp.Body)
respData, err = io.ReadAll(resp.Body)
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
if err != nil {
respData = []byte(err.Error())
Expand Down

0 comments on commit c4ee43c

Please sign in to comment.