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