Maintenance: use io instead of ioutil if possible
This commit is contained in:
@@ -3,7 +3,7 @@ package cli
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
@@ -20,7 +20,7 @@ func (c *cli) ClientKey(args []string, openFile os.OpenFileFunc) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := ioutil.ReadAll(file)
|
||||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return err
|
||||
|
||||
@@ -3,7 +3,7 @@ package configuration
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/qdm12/golibs/os"
|
||||
@@ -49,7 +49,7 @@ func (r *reader) getFromEnvOrSecretFile(envKey string, compulsory bool, retroKey
|
||||
return "", fmt.Errorf("%w: %s", ErrReadSecretFile, fileErr)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(file)
|
||||
b, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("%w: %s", ErrReadSecretFile, err)
|
||||
}
|
||||
@@ -97,7 +97,7 @@ func readFromFile(openFile os.OpenFileFunc, filepath string) (b []byte, err erro
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err = ioutil.ReadAll(file)
|
||||
b, err = io.ReadAll(file)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return nil, err
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -199,7 +199,7 @@ func (c *configurator) runUserPostRules(ctx context.Context, filepath string, re
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := ioutil.ReadAll(file)
|
||||
b, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return err
|
||||
|
||||
@@ -3,7 +3,7 @@ package healthcheck
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -34,7 +34,7 @@ func (h *checker) Check(ctx context.Context, url string) error {
|
||||
if response.StatusCode == http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
b, err := ioutil.ReadAll(response.Body)
|
||||
b, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package openvpn
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -34,7 +34,7 @@ func (c *configurator) WriteAuthFile(user, password string, puid, pgid int) erro
|
||||
return file.Close()
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(file)
|
||||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return err
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -326,7 +326,7 @@ func getOpenvpnCredentials(openFile os.OpenFileFunc) (username, password string,
|
||||
return "", "", fmt.Errorf("%w: %s", errAuthFileRead, err)
|
||||
}
|
||||
|
||||
authData, err := ioutil.ReadAll(file)
|
||||
authData, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return "", "", fmt.Errorf("%w: %s", errAuthFileRead, err)
|
||||
@@ -495,7 +495,7 @@ func makeNOKStatusError(response *http.Response, substitutions map[string]string
|
||||
url := response.Request.URL.String()
|
||||
url = replaceInString(url, substitutions)
|
||||
|
||||
b, _ := ioutil.ReadAll(response.Body)
|
||||
b, _ := io.ReadAll(response.Body)
|
||||
shortenMessage := string(b)
|
||||
shortenMessage = strings.ReplaceAll(shortenMessage, "\n", "")
|
||||
shortenMessage = strings.ReplaceAll(shortenMessage, " ", " ")
|
||||
|
||||
@@ -4,7 +4,7 @@ package publicip
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -55,7 +55,7 @@ func (i *ipGetter) Get(ctx context.Context) (ip net.IP, err error) {
|
||||
return nil, fmt.Errorf("%w from %s: %s", ErrBadStatusCode, url, response.Status)
|
||||
}
|
||||
|
||||
content, err := ioutil.ReadAll(response.Body)
|
||||
content, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %s", ErrCannotReadBody, err)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
@@ -54,7 +54,7 @@ func fetchAPI(ctx context.Context, client *http.Client) (
|
||||
return data, fmt.Errorf("%w: %s", ErrHTTPStatusCodeNotOK, response.Status)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(response.Body)
|
||||
b, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package unzip
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
@@ -24,7 +24,7 @@ func zipExtractAll(zipBytes []byte) (contents map[string][]byte, err error) {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
contents[fileName], err = ioutil.ReadAll(f)
|
||||
contents[fileName], err = io.ReadAll(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -31,7 +31,7 @@ func (u *unzipper) FetchAndExtract(ctx context.Context, url string) (
|
||||
return nil, fmt.Errorf("%w: %s for %s", ErrHTTPStatusCodeNotOK, response.Status, url)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadAll(response.Body)
|
||||
b, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user