refactor: stop using deprecated io/ioutil
This commit is contained in:
@@ -2,14 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func run() error {
|
||||
tfb, err := ioutil.ReadFile("./node/config/types.go")
|
||||
tfb, err := os.ReadFile("./node/config/types.go")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
@@ -47,7 +46,7 @@ func FromFile(path string, opts ...LoadCfgOpt) (interface{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close() //nolint:errcheck,staticcheck // The file is RO
|
||||
cfgBs, err := ioutil.ReadAll(file)
|
||||
cfgBs, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to read config for validation checks %w", err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -50,7 +49,7 @@ func TestParitalConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
f, err := ioutil.TempFile("", "config-*.toml")
|
||||
f, err := os.CreateTemp("", "config-*.toml")
|
||||
fname := f.Name()
|
||||
|
||||
assert.NoError(err, "tmp file shold not error")
|
||||
@@ -115,7 +114,7 @@ func TestValidateConfigSetsEnableSplitstore(t *testing.T) {
|
||||
assert.False(t, MatchEnableSplitstoreField(string(cfgCommentedOutEnableSS)))
|
||||
|
||||
// write config with commented out EnableSplitstore to file
|
||||
f, err := ioutil.TempFile("", "config.toml")
|
||||
f, err := os.CreateTemp("", "config.toml")
|
||||
fname := f.Name()
|
||||
assert.NoError(t, err)
|
||||
defer func() {
|
||||
@@ -132,7 +131,7 @@ func TestValidateConfigSetsEnableSplitstore(t *testing.T) {
|
||||
|
||||
// Loading without a config file and a default fails if the default fallback is disabled
|
||||
func TestFailToFallbackToDefault(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "dirWithNoFiles")
|
||||
dir, err := os.MkdirTemp("", "dirWithNoFiles")
|
||||
assert.NoError(t, err)
|
||||
defer assert.NoError(t, os.RemoveAll(dir))
|
||||
nonExistantFileName := dir + "/notarealfile"
|
||||
|
||||
@@ -3,7 +3,6 @@ package config
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
@@ -43,7 +42,7 @@ func WriteStorageFile(path string, config storiface.StorageConfig) error {
|
||||
return xerrors.Errorf("marshaling storage config: %w", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(path, b, 0644); err != nil {
|
||||
if err := os.WriteFile(path, b, 0644); err != nil {
|
||||
return xerrors.Errorf("persisting storage config (%s): %w", path, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user