From 07508ac0e9695df347b9dd00d418c25151fbb213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Mon, 16 May 2022 11:59:35 +0200 Subject: [PATCH] all: replace uses of ioutil with io and os (#24869) --- accounts/abi/bind/auth.go | 5 ++--- accounts/keystore/account_cache_test.go | 9 ++++----- accounts/keystore/key.go | 3 +-- accounts/keystore/passphrase.go | 3 +-- accounts/keystore/passphrase_test.go | 4 ++-- accounts/scwallet/hub.go | 4 ++-- build/ci.go | 5 ++--- build/update-license.go | 9 ++++----- cmd/abigen/main.go | 12 ++++++------ cmd/clef/main.go | 7 +++---- cmd/devp2p/dnscmd.go | 7 +++---- cmd/devp2p/enrcmd.go | 5 ++--- cmd/devp2p/internal/ethtest/chain.go | 3 +-- cmd/devp2p/nodeset.go | 3 +-- cmd/ethkey/changepassword.go | 8 ++++---- cmd/ethkey/generate.go | 3 +-- cmd/ethkey/inspect.go | 4 ++-- cmd/ethkey/message.go | 6 +++--- cmd/ethkey/utils.go | 4 ++-- cmd/evm/compiler.go | 4 ++-- cmd/evm/disasm.go | 4 ++-- cmd/evm/internal/t8ntool/transition.go | 3 +-- cmd/evm/runner.go | 10 +++++----- cmd/evm/staterunner.go | 3 +-- cmd/faucet/faucet.go | 10 +++++----- cmd/geth/accountcmd.go | 4 ++-- cmd/geth/accountcmd_test.go | 5 +++-- cmd/geth/dao_test.go | 4 ++-- cmd/geth/genesis_test.go | 4 ++-- cmd/geth/version_check.go | 7 ++++--- cmd/geth/version_check_test.go | 7 ++++--- cmd/puppeth/genesis_test.go | 10 +++++----- cmd/puppeth/ssh.go | 3 +-- cmd/puppeth/wizard.go | 3 +-- cmd/puppeth/wizard_genesis.go | 5 ++--- cmd/puppeth/wizard_intro.go | 3 +-- cmd/utils/flags.go | 3 +-- common/compiler/helpers.go | 4 ++-- common/test_utils.go | 4 ++-- consensus/ethash/algorithm_test.go | 3 +-- consensus/ethash/ethash_test.go | 3 +-- consensus/ethash/sealer_test.go | 10 +++++----- console/console.go | 5 ++--- core/rawdb/accessors_chain_test.go | 4 ++-- core/rawdb/freezer_meta_test.go | 5 ++--- core/rawdb/freezer_utils.go | 3 +-- core/rawdb/freezer_utils_test.go | 5 ++--- core/tx_pool_test.go | 3 +-- core/vm/contracts_test.go | 6 +++--- core/vm/instructions_test.go | 6 +++--- crypto/crypto.go | 3 +-- crypto/crypto_test.go | 5 ++--- crypto/signify/signify.go | 6 +++--- crypto/signify/signify_fuzz.go | 7 +++---- crypto/signify/signify_test.go | 9 ++++----- eth/tracers/api.go | 5 ++--- eth/tracers/internal/tracetest/calltrace_test.go | 5 +++-- graphql/graphql_test.go | 6 +++--- internal/build/download.go | 3 +-- internal/build/util.go | 2 +- internal/cmdtest/test_cmd.go | 3 +-- internal/jsre/jsre.go | 6 +++--- internal/jsre/jsre_test.go | 3 +-- internal/utesting/utesting.go | 3 +-- les/api_test.go | 3 +-- metrics/librato/client.go | 4 ++-- metrics/metrics_test.go | 6 +++--- miner/stress/1559/main.go | 3 +-- miner/stress/beacon/main.go | 5 ++--- miner/stress/clique/main.go | 3 +-- miner/stress/ethash/main.go | 3 +-- mobile/android_test.go | 7 +++---- node/config.go | 3 +-- node/config_test.go | 7 +++---- node/rpcstack.go | 3 +-- p2p/discover/v5wire/encoding_test.go | 3 +-- p2p/message.go | 5 ++--- p2p/simulations/examples/ping-pong.go | 6 +++--- p2p/simulations/http.go | 5 ++--- rlp/encode_test.go | 5 ++--- rlp/rlpgen/gen_test.go | 7 +++---- rlp/rlpgen/main.go | 3 +-- rpc/http.go | 5 ++--- rpc/server_test.go | 3 ++- signer/core/signed_data_test.go | 5 +++-- signer/core/uiapi.go | 4 ++-- signer/fourbyte/fourbyte.go | 5 ++--- signer/storage/aes_gcm_storage.go | 5 ++--- signer/storage/aes_gcm_storage_test.go | 6 +++--- tests/fuzzers/abi/abifuzzer_test.go | 2 +- tests/fuzzers/difficulty/debug/main.go | 3 +-- tests/fuzzers/les/debug/main.go | 3 +-- tests/fuzzers/rangeproof/debug/main.go | 3 +-- tests/fuzzers/snap/debug/main.go | 3 +-- tests/fuzzers/stacktrie/debug/main.go | 3 +-- tests/fuzzers/vflux/debug/main.go | 3 +-- tests/init_test.go | 3 +-- 97 files changed, 203 insertions(+), 257 deletions(-) diff --git a/accounts/abi/bind/auth.go b/accounts/abi/bind/auth.go index a4307a9529..494dc88a57 100644 --- a/accounts/abi/bind/auth.go +++ b/accounts/abi/bind/auth.go @@ -21,7 +21,6 @@ import ( "crypto/ecdsa" "errors" "io" - "io/ioutil" "math/big" "github.com/ethereum/go-ethereum/accounts" @@ -45,7 +44,7 @@ var ErrNotAuthorized = errors.New("not authorized to sign this account") // Deprecated: Use NewTransactorWithChainID instead. func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) { log.Warn("WARNING: NewTransactor has been deprecated in favour of NewTransactorWithChainID") - json, err := ioutil.ReadAll(keyin) + json, err := io.ReadAll(keyin) if err != nil { return nil, err } @@ -106,7 +105,7 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts { // NewTransactorWithChainID is a utility method to easily create a transaction signer from // an encrypted json key stream and the associated passphrase. func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) { - json, err := ioutil.ReadAll(keyin) + json, err := io.ReadAll(keyin) if err != nil { return nil, err } diff --git a/accounts/keystore/account_cache_test.go b/accounts/keystore/account_cache_test.go index e6df617126..fda0e5667c 100644 --- a/accounts/keystore/account_cache_test.go +++ b/accounts/keystore/account_cache_test.go @@ -18,7 +18,6 @@ package keystore import ( "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -380,11 +379,11 @@ func TestUpdatedKeyfileContents(t *testing.T) { return } - // needed so that modTime of `file` is different to its current value after ioutil.WriteFile + // needed so that modTime of `file` is different to its current value after os.WriteFile time.Sleep(1000 * time.Millisecond) // Now replace file contents with crap - if err := ioutil.WriteFile(file, []byte("foo"), 0644); err != nil { + if err := os.WriteFile(file, []byte("foo"), 0644); err != nil { t.Fatal(err) return } @@ -397,9 +396,9 @@ func TestUpdatedKeyfileContents(t *testing.T) { // forceCopyFile is like cp.CopyFile, but doesn't complain if the destination exists. func forceCopyFile(dst, src string) error { - data, err := ioutil.ReadFile(src) + data, err := os.ReadFile(src) if err != nil { return err } - return ioutil.WriteFile(dst, data, 0644) + return os.WriteFile(dst, data, 0644) } diff --git a/accounts/keystore/key.go b/accounts/keystore/key.go index 2b815ce0f9..9b2ac14712 100644 --- a/accounts/keystore/key.go +++ b/accounts/keystore/key.go @@ -23,7 +23,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -197,7 +196,7 @@ func writeTemporaryKeyFile(file string, content []byte) (string, error) { } // Atomic write: create a temporary hidden file first // then move it into place. TempFile assigns mode 0600. - f, err := ioutil.TempFile(filepath.Dir(file), "."+filepath.Base(file)+".tmp") + f, err := os.CreateTemp(filepath.Dir(file), "."+filepath.Base(file)+".tmp") if err != nil { return "", err } diff --git a/accounts/keystore/passphrase.go b/accounts/keystore/passphrase.go index 3b3e631888..22772e9310 100644 --- a/accounts/keystore/passphrase.go +++ b/accounts/keystore/passphrase.go @@ -34,7 +34,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" @@ -82,7 +81,7 @@ type keyStorePassphrase struct { func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string) (*Key, error) { // Load the key from the keystore and decrypt its contents - keyjson, err := ioutil.ReadFile(filename) + keyjson, err := os.ReadFile(filename) if err != nil { return nil, err } diff --git a/accounts/keystore/passphrase_test.go b/accounts/keystore/passphrase_test.go index 630682cebd..b94fce8edc 100644 --- a/accounts/keystore/passphrase_test.go +++ b/accounts/keystore/passphrase_test.go @@ -17,7 +17,7 @@ package keystore import ( - "io/ioutil" + "os" "testing" "github.com/ethereum/go-ethereum/common" @@ -30,7 +30,7 @@ const ( // Tests that a json key file can be decrypted and encrypted in multiple rounds. func TestKeyEncryptDecrypt(t *testing.T) { - keyjson, err := ioutil.ReadFile("testdata/very-light-scrypt.json") + keyjson, err := os.ReadFile("testdata/very-light-scrypt.json") if err != nil { t.Fatal(err) } diff --git a/accounts/scwallet/hub.go b/accounts/scwallet/hub.go index 811f8c695e..f9dcf58e19 100644 --- a/accounts/scwallet/hub.go +++ b/accounts/scwallet/hub.go @@ -34,7 +34,7 @@ package scwallet import ( "encoding/json" - "io/ioutil" + "io" "os" "path/filepath" "sort" @@ -96,7 +96,7 @@ func (hub *Hub) readPairings() error { return err } - pairingData, err := ioutil.ReadAll(pairingFile) + pairingData, err := io.ReadAll(pairingFile) if err != nil { return err } diff --git a/build/ci.go b/build/ci.go index 4c334db876..4129168be5 100644 --- a/build/ci.go +++ b/build/ci.go @@ -46,7 +46,6 @@ import ( "encoding/base64" "flag" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -736,7 +735,7 @@ func ppaUpload(workdir, ppa, sshUser string, files []string) { if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 { idfile = filepath.Join(workdir, "sshkey") if !common.FileExist(idfile) { - ioutil.WriteFile(idfile, sshkey, 0600) + os.WriteFile(idfile, sshkey, 0600) } } // Upload @@ -759,7 +758,7 @@ func makeWorkdir(wdflag string) string { if wdflag != "" { err = os.MkdirAll(wdflag, 0744) } else { - wdflag, err = ioutil.TempDir("", "geth-build-") + wdflag, err = os.MkdirTemp("", "geth-build-") } if err != nil { log.Fatal(err) diff --git a/build/update-license.go b/build/update-license.go index aa4d6100d7..641162ee35 100644 --- a/build/update-license.go +++ b/build/update-license.go @@ -39,7 +39,6 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -241,7 +240,7 @@ func gitAuthors(files []string) []string { } func readAuthors() []string { - content, err := ioutil.ReadFile("AUTHORS") + content, err := os.ReadFile("AUTHORS") if err != nil && !os.IsNotExist(err) { log.Fatalln("error reading AUTHORS:", err) } @@ -305,7 +304,7 @@ func writeAuthors(files []string) { content.WriteString("\n") } fmt.Println("writing AUTHORS") - if err := ioutil.WriteFile("AUTHORS", content.Bytes(), 0644); err != nil { + if err := os.WriteFile("AUTHORS", content.Bytes(), 0644); err != nil { log.Fatalln(err) } } @@ -381,7 +380,7 @@ func writeLicense(info *info) { if err != nil { log.Fatalf("error stat'ing %s: %v\n", info.file, err) } - content, err := ioutil.ReadFile(info.file) + content, err := os.ReadFile(info.file) if err != nil { log.Fatalf("error reading %s: %v\n", info.file, err) } @@ -400,7 +399,7 @@ func writeLicense(info *info) { return } fmt.Println("writing", info.ShortLicense(), info.file) - if err := ioutil.WriteFile(info.file, buf.Bytes(), fi.Mode()); err != nil { + if err := os.WriteFile(info.file, buf.Bytes(), fi.Mode()); err != nil { log.Fatalf("error writing %s: %v", info.file, err) } } diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go index 7b3b35e4e5..911aada379 100644 --- a/cmd/abigen/main.go +++ b/cmd/abigen/main.go @@ -19,7 +19,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "regexp" @@ -155,9 +155,9 @@ func abigen(c *cli.Context) error { ) input := c.GlobalString(abiFlag.Name) if input == "-" { - abi, err = ioutil.ReadAll(os.Stdin) + abi, err = io.ReadAll(os.Stdin) } else { - abi, err = ioutil.ReadFile(input) + abi, err = os.ReadFile(input) } if err != nil { utils.Fatalf("Failed to read input ABI: %v", err) @@ -166,7 +166,7 @@ func abigen(c *cli.Context) error { var bin []byte if binFile := c.GlobalString(binFlag.Name); binFile != "" { - if bin, err = ioutil.ReadFile(binFile); err != nil { + if bin, err = os.ReadFile(binFile); err != nil { utils.Fatalf("Failed to read input bytecode: %v", err) } if strings.Contains(string(bin), "//") { @@ -213,7 +213,7 @@ func abigen(c *cli.Context) error { } case c.GlobalIsSet(jsonFlag.Name): - jsonOutput, err := ioutil.ReadFile(c.GlobalString(jsonFlag.Name)) + jsonOutput, err := os.ReadFile(c.GlobalString(jsonFlag.Name)) if err != nil { utils.Fatalf("Failed to read combined-json from compiler: %v", err) } @@ -263,7 +263,7 @@ func abigen(c *cli.Context) error { fmt.Printf("%s\n", code) return nil } - if err := ioutil.WriteFile(c.GlobalString(outFlag.Name), []byte(code), 0600); err != nil { + if err := os.WriteFile(c.GlobalString(outFlag.Name), []byte(code), 0600); err != nil { utils.Fatalf("Failed to write ABI binding: %v", err) } return nil diff --git a/cmd/clef/main.go b/cmd/clef/main.go index f7c3adebc4..b1ffa38ffe 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -25,7 +25,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/big" "os" "os/signal" @@ -374,7 +373,7 @@ func initializeSecrets(c *cli.Context) error { return fmt.Errorf("master key %v already exists, will not overwrite", location) } // Write the file and print the usual warning message - if err = ioutil.WriteFile(location, cipherSeed, 0400); err != nil { + if err = os.WriteFile(location, cipherSeed, 0400); err != nil { return err } fmt.Printf("A master seed has been generated into %s\n", location) @@ -593,7 +592,7 @@ func signer(c *cli.Context) error { // Do we have a rule-file? if ruleFile := c.GlobalString(ruleFlag.Name); ruleFile != "" { - ruleJS, err := ioutil.ReadFile(ruleFile) + ruleJS, err := os.ReadFile(ruleFile) if err != nil { log.Warn("Could not load rules, disabling", "file", ruleFile, "err", err) } else { @@ -751,7 +750,7 @@ func readMasterKey(ctx *cli.Context, ui core.UIClientAPI) ([]byte, error) { if err := checkFile(file); err != nil { return nil, err } - cipherKey, err := ioutil.ReadFile(file) + cipherKey, err := os.ReadFile(file) if err != nil { return nil, err } diff --git a/cmd/devp2p/dnscmd.go b/cmd/devp2p/dnscmd.go index 85f28b8cb1..afdc614f0e 100644 --- a/cmd/devp2p/dnscmd.go +++ b/cmd/devp2p/dnscmd.go @@ -20,7 +20,6 @@ import ( "crypto/ecdsa" "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "time" @@ -253,7 +252,7 @@ func dnsNukeRoute53(ctx *cli.Context) error { // loadSigningKey loads a private key in Ethereum keystore format. func loadSigningKey(keyfile string) *ecdsa.PrivateKey { - keyjson, err := ioutil.ReadFile(keyfile) + keyjson, err := os.ReadFile(keyfile) if err != nil { exit(fmt.Errorf("failed to read the keyfile at '%s': %v", keyfile, err)) } @@ -382,7 +381,7 @@ func writeTreeMetadata(directory string, def *dnsDefinition) { exit(err) } metaFile, _ := treeDefinitionFiles(directory) - if err := ioutil.WriteFile(metaFile, metaJSON, 0644); err != nil { + if err := os.WriteFile(metaFile, metaJSON, 0644); err != nil { exit(err) } } @@ -411,7 +410,7 @@ func writeTXTJSON(file string, txt map[string]string) { fmt.Println() return } - if err := ioutil.WriteFile(file, txtJSON, 0644); err != nil { + if err := os.WriteFile(file, txtJSON, 0644); err != nil { exit(err) } } diff --git a/cmd/devp2p/enrcmd.go b/cmd/devp2p/enrcmd.go index a1a68c5647..2a8f9d508f 100644 --- a/cmd/devp2p/enrcmd.go +++ b/cmd/devp2p/enrcmd.go @@ -22,7 +22,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "net" "os" "strconv" @@ -54,9 +53,9 @@ func enrdump(ctx *cli.Context) error { var b []byte var err error if file == "-" { - b, err = ioutil.ReadAll(os.Stdin) + b, err = io.ReadAll(os.Stdin) } else { - b, err = ioutil.ReadFile(file) + b, err = os.ReadFile(file) } if err != nil { return err diff --git a/cmd/devp2p/internal/ethtest/chain.go b/cmd/devp2p/internal/ethtest/chain.go index d0d55a455d..ee47ed7edf 100644 --- a/cmd/devp2p/internal/ethtest/chain.go +++ b/cmd/devp2p/internal/ethtest/chain.go @@ -21,7 +21,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/big" "os" "strings" @@ -153,7 +152,7 @@ func loadChain(chainfile string, genesis string) (*Chain, error) { } func loadGenesis(genesisFile string) (core.Genesis, error) { - chainConfig, err := ioutil.ReadFile(genesisFile) + chainConfig, err := os.ReadFile(genesisFile) if err != nil { return core.Genesis{}, err } diff --git a/cmd/devp2p/nodeset.go b/cmd/devp2p/nodeset.go index 1d78e34c73..33c39f4b9e 100644 --- a/cmd/devp2p/nodeset.go +++ b/cmd/devp2p/nodeset.go @@ -20,7 +20,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "os" "sort" "time" @@ -66,7 +65,7 @@ func writeNodesJSON(file string, nodes nodeSet) { os.Stdout.Write(nodesJSON) return } - if err := ioutil.WriteFile(file, nodesJSON, 0644); err != nil { + if err := os.WriteFile(file, nodesJSON, 0644); err != nil { exit(err) } } diff --git a/cmd/ethkey/changepassword.go b/cmd/ethkey/changepassword.go index b9402c2f96..bd8745f6db 100644 --- a/cmd/ethkey/changepassword.go +++ b/cmd/ethkey/changepassword.go @@ -18,7 +18,7 @@ package main import ( "fmt" - "io/ioutil" + "os" "strings" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -45,7 +45,7 @@ Change the password of a keyfile.`, keyfilepath := ctx.Args().First() // Read key from file. - keyjson, err := ioutil.ReadFile(keyfilepath) + keyjson, err := os.ReadFile(keyfilepath) if err != nil { utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) } @@ -61,7 +61,7 @@ Change the password of a keyfile.`, fmt.Println("Please provide a new password") var newPhrase string if passFile := ctx.String(newPassphraseFlag.Name); passFile != "" { - content, err := ioutil.ReadFile(passFile) + content, err := os.ReadFile(passFile) if err != nil { utils.Fatalf("Failed to read new password file '%s': %v", passFile, err) } @@ -77,7 +77,7 @@ Change the password of a keyfile.`, } // Then write the new keyfile in place of the old one. - if err := ioutil.WriteFile(keyfilepath, newJson, 0600); err != nil { + if err := os.WriteFile(keyfilepath, newJson, 0600); err != nil { utils.Fatalf("Error writing new keyfile to disk: %v", err) } diff --git a/cmd/ethkey/generate.go b/cmd/ethkey/generate.go index b444a345ac..1b70b130bc 100644 --- a/cmd/ethkey/generate.go +++ b/cmd/ethkey/generate.go @@ -19,7 +19,6 @@ package main import ( "crypto/ecdsa" "fmt" - "io/ioutil" "os" "path/filepath" @@ -116,7 +115,7 @@ If you want to encrypt an existing private key, it can be specified by setting if err := os.MkdirAll(filepath.Dir(keyfilepath), 0700); err != nil { utils.Fatalf("Could not create directory %s", filepath.Dir(keyfilepath)) } - if err := ioutil.WriteFile(keyfilepath, keyjson, 0600); err != nil { + if err := os.WriteFile(keyfilepath, keyjson, 0600); err != nil { utils.Fatalf("Failed to write keyfile to %s: %v", keyfilepath, err) } diff --git a/cmd/ethkey/inspect.go b/cmd/ethkey/inspect.go index 1cb91ecfe6..efcaecd389 100644 --- a/cmd/ethkey/inspect.go +++ b/cmd/ethkey/inspect.go @@ -19,7 +19,7 @@ package main import ( "encoding/hex" "fmt" - "io/ioutil" + "os" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" @@ -58,7 +58,7 @@ make sure to use this feature with great caution!`, keyfilepath := ctx.Args().First() // Read key from file. - keyjson, err := ioutil.ReadFile(keyfilepath) + keyjson, err := os.ReadFile(keyfilepath) if err != nil { utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) } diff --git a/cmd/ethkey/message.go b/cmd/ethkey/message.go index b23c23f658..1a58eeb536 100644 --- a/cmd/ethkey/message.go +++ b/cmd/ethkey/message.go @@ -19,7 +19,7 @@ package main import ( "encoding/hex" "fmt" - "io/ioutil" + "os" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" @@ -56,7 +56,7 @@ To sign a message contained in a file, use the --msgfile flag. // Load the keyfile. keyfilepath := ctx.Args().First() - keyjson, err := ioutil.ReadFile(keyfilepath) + keyjson, err := os.ReadFile(keyfilepath) if err != nil { utils.Fatalf("Failed to read the keyfile at '%s': %v", keyfilepath, err) } @@ -146,7 +146,7 @@ func getMessage(ctx *cli.Context, msgarg int) []byte { if len(ctx.Args()) > msgarg { utils.Fatalf("Can't use --msgfile and message argument at the same time.") } - msg, err := ioutil.ReadFile(file) + msg, err := os.ReadFile(file) if err != nil { utils.Fatalf("Can't read message file: %v", err) } diff --git a/cmd/ethkey/utils.go b/cmd/ethkey/utils.go index 70baae92f4..b81e70913b 100644 --- a/cmd/ethkey/utils.go +++ b/cmd/ethkey/utils.go @@ -19,7 +19,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "os" "strings" "github.com/ethereum/go-ethereum/cmd/utils" @@ -34,7 +34,7 @@ func getPassphrase(ctx *cli.Context, confirmation bool) string { // Look for the --passwordfile flag. passphraseFile := ctx.String(passphraseFlag.Name) if passphraseFile != "" { - content, err := ioutil.ReadFile(passphraseFile) + content, err := os.ReadFile(passphraseFile) if err != nil { utils.Fatalf("Failed to read password file '%s': %v", passphraseFile, err) diff --git a/cmd/evm/compiler.go b/cmd/evm/compiler.go index 40ad9313c5..880f995f05 100644 --- a/cmd/evm/compiler.go +++ b/cmd/evm/compiler.go @@ -19,7 +19,7 @@ package main import ( "errors" "fmt" - "io/ioutil" + "os" "github.com/ethereum/go-ethereum/cmd/evm/internal/compiler" @@ -41,7 +41,7 @@ func compileCmd(ctx *cli.Context) error { } fn := ctx.Args().First() - src, err := ioutil.ReadFile(fn) + src, err := os.ReadFile(fn) if err != nil { return err } diff --git a/cmd/evm/disasm.go b/cmd/evm/disasm.go index f9719497fe..918b013767 100644 --- a/cmd/evm/disasm.go +++ b/cmd/evm/disasm.go @@ -19,7 +19,7 @@ package main import ( "errors" "fmt" - "io/ioutil" + "os" "strings" "github.com/ethereum/go-ethereum/core/asm" @@ -38,7 +38,7 @@ func disasmCmd(ctx *cli.Context) error { switch { case len(ctx.Args().First()) > 0: fn := ctx.Args().First() - input, err := ioutil.ReadFile(fn) + input, err := os.ReadFile(fn) if err != nil { return err } diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 6406ccf6a4..b254baa995 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -21,7 +21,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math/big" "os" "path" @@ -401,7 +400,7 @@ func saveFile(baseDir, filename string, data interface{}) error { return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err)) } location := path.Join(baseDir, filename) - if err = ioutil.WriteFile(location, b, 0644); err != nil { + if err = os.WriteFile(location, b, 0644); err != nil { return NewError(ErrorIO, fmt.Errorf("failed writing output: %v", err)) } log.Info("Wrote file", "file", location) diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 2afce8eb0f..5680c07a40 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -20,7 +20,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "math/big" "os" goruntime "runtime" @@ -165,13 +165,13 @@ func runCmd(ctx *cli.Context) error { // If - is specified, it means that code comes from stdin if codeFileFlag == "-" { //Try reading from stdin - if hexcode, err = ioutil.ReadAll(os.Stdin); err != nil { + if hexcode, err = io.ReadAll(os.Stdin); err != nil { fmt.Printf("Could not load code from stdin: %v\n", err) os.Exit(1) } } else { // Codefile with hex assembly - if hexcode, err = ioutil.ReadFile(codeFileFlag); err != nil { + if hexcode, err = os.ReadFile(codeFileFlag); err != nil { fmt.Printf("Could not load code from file: %v\n", err) os.Exit(1) } @@ -187,7 +187,7 @@ func runCmd(ctx *cli.Context) error { code = common.FromHex(string(hexcode)) } else if fn := ctx.Args().First(); len(fn) > 0 { // EASM-file to compile - src, err := ioutil.ReadFile(fn) + src, err := os.ReadFile(fn) if err != nil { return err } @@ -239,7 +239,7 @@ func runCmd(ctx *cli.Context) error { var hexInput []byte if inputFileFlag := ctx.GlobalString(InputFileFlag.Name); inputFileFlag != "" { var err error - if hexInput, err = ioutil.ReadFile(inputFileFlag); err != nil { + if hexInput, err = os.ReadFile(inputFileFlag); err != nil { fmt.Printf("could not load input from file: %v\n", err) os.Exit(1) } diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index 90596d9b3c..fcdac33eed 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -20,7 +20,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/core/state" @@ -81,7 +80,7 @@ func stateTestCmd(ctx *cli.Context) error { debugger = logger.NewStructLogger(config) } // Load the test content from the input file - src, err := ioutil.ReadFile(ctx.Args().First()) + src, err := os.ReadFile(ctx.Args().First()) if err != nil { return err } diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index bcf28bd584..bcb837062f 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -26,7 +26,7 @@ import ( "flag" "fmt" "html/template" - "io/ioutil" + "io" "math" "math/big" "net/http" @@ -157,14 +157,14 @@ func main() { } } // Load up the account key and decrypt its password - blob, err := ioutil.ReadFile(*accPassFlag) + blob, err := os.ReadFile(*accPassFlag) if err != nil { log.Crit("Failed to read account password contents", "file", *accPassFlag, "err", err) } pass := strings.TrimSuffix(string(blob), "\n") ks := keystore.NewKeyStore(filepath.Join(os.Getenv("HOME"), ".faucet", "keys"), keystore.StandardScryptN, keystore.StandardScryptP) - if blob, err = ioutil.ReadFile(*accJSONFlag); err != nil { + if blob, err = os.ReadFile(*accJSONFlag); err != nil { log.Crit("Failed to read account key contents", "file", *accJSONFlag, "err", err) } acc, err := ks.Import(blob, pass, pass) @@ -727,7 +727,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c } username := parts[len(parts)-3] - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return "", "", "", common.Address{}, err } @@ -853,7 +853,7 @@ func authFacebook(url string) (string, string, common.Address, error) { } defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return "", "", common.Address{}, err } diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index e33b9eb0fb..0b7d58e888 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -18,7 +18,7 @@ package main import ( "fmt" - "io/ioutil" + "os" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -320,7 +320,7 @@ func importWallet(ctx *cli.Context) error { if len(keyfile) == 0 { utils.Fatalf("keyfile must be given as argument") } - keyJSON, err := ioutil.ReadFile(keyfile) + keyJSON, err := os.ReadFile(keyfile) if err != nil { utils.Fatalf("Could not read wallet file: %v", err) } diff --git a/cmd/geth/accountcmd_test.go b/cmd/geth/accountcmd_test.go index 843117eb5a..6b3a56211c 100644 --- a/cmd/geth/accountcmd_test.go +++ b/cmd/geth/accountcmd_test.go @@ -18,6 +18,7 @@ package main import ( "io/ioutil" + "os" "path/filepath" "runtime" "strings" @@ -113,11 +114,11 @@ func TestAccountImport(t *testing.T) { func importAccountWithExpect(t *testing.T, key string, expected string) { dir := t.TempDir() keyfile := filepath.Join(dir, "key.prv") - if err := ioutil.WriteFile(keyfile, []byte(key), 0600); err != nil { + if err := os.WriteFile(keyfile, []byte(key), 0600); err != nil { t.Error(err) } passwordFile := filepath.Join(dir, "password.txt") - if err := ioutil.WriteFile(passwordFile, []byte("foobar"), 0600); err != nil { + if err := os.WriteFile(passwordFile, []byte("foobar"), 0600); err != nil { t.Error(err) } geth := runGeth(t, "--lightkdf", "account", "import", keyfile, "-password", passwordFile) diff --git a/cmd/geth/dao_test.go b/cmd/geth/dao_test.go index d3cbfd156d..0701a2d5a2 100644 --- a/cmd/geth/dao_test.go +++ b/cmd/geth/dao_test.go @@ -17,8 +17,8 @@ package main import ( - "io/ioutil" "math/big" + "os" "path/filepath" "testing" @@ -110,7 +110,7 @@ func testDAOForkBlockNewChain(t *testing.T, test int, genesis string, expectBloc // Start a Geth instance with the requested flags set and immediately terminate if genesis != "" { json := filepath.Join(datadir, "genesis.json") - if err := ioutil.WriteFile(json, []byte(genesis), 0600); err != nil { + if err := os.WriteFile(json, []byte(genesis), 0600); err != nil { t.Fatalf("test %d: failed to write genesis file: %v", test, err) } runGeth(t, "--datadir", datadir, "--networkid", "1337", "init", json).WaitExit() diff --git a/cmd/geth/genesis_test.go b/cmd/geth/genesis_test.go index fb047f55cf..c95755f2d9 100644 --- a/cmd/geth/genesis_test.go +++ b/cmd/geth/genesis_test.go @@ -17,7 +17,7 @@ package main import ( - "io/ioutil" + "os" "path/filepath" "testing" ) @@ -76,7 +76,7 @@ func TestCustomGenesis(t *testing.T) { // Initialize the data directory with the custom genesis block json := filepath.Join(datadir, "genesis.json") - if err := ioutil.WriteFile(json, []byte(tt.genesis), 0600); err != nil { + if err := os.WriteFile(json, []byte(tt.genesis), 0600); err != nil { t.Fatalf("test %d: failed to write genesis file: %v", i, err) } runGeth(t, "--datadir", datadir, "init", json).WaitExit() diff --git a/cmd/geth/version_check.go b/cmd/geth/version_check.go index 2101a69e98..6eaedf3734 100644 --- a/cmd/geth/version_check.go +++ b/cmd/geth/version_check.go @@ -20,8 +20,9 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" + "os" "regexp" "strings" @@ -112,14 +113,14 @@ func checkCurrent(url, current string) error { // fetch makes an HTTP request to the given url and returns the response body func fetch(url string) ([]byte, error) { if filep := strings.TrimPrefix(url, "file://"); filep != url { - return ioutil.ReadFile(filep) + return os.ReadFile(filep) } res, err := http.Get(url) if err != nil { return nil, err } defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return nil, err } diff --git a/cmd/geth/version_check_test.go b/cmd/geth/version_check_test.go index 4be32d5e4f..69d5e65c9c 100644 --- a/cmd/geth/version_check_test.go +++ b/cmd/geth/version_check_test.go @@ -20,6 +20,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "os" "path/filepath" "regexp" "strconv" @@ -49,7 +50,7 @@ func TestVerification(t *testing.T) { func testVerification(t *testing.T, pubkey, sigdir string) { // Data to verify - data, err := ioutil.ReadFile("./testdata/vcheck/data.json") + data, err := os.ReadFile("./testdata/vcheck/data.json") if err != nil { t.Fatal(err) } @@ -59,7 +60,7 @@ func testVerification(t *testing.T, pubkey, sigdir string) { t.Fatal(err) } for _, f := range files { - sig, err := ioutil.ReadFile(filepath.Join(sigdir, f.Name())) + sig, err := os.ReadFile(filepath.Join(sigdir, f.Name())) if err != nil { t.Fatal(err) } @@ -87,7 +88,7 @@ func versionUint(v string) int { // TestMatching can be used to check that the regexps are correct func TestMatching(t *testing.T) { - data, _ := ioutil.ReadFile("./testdata/vcheck/vulnerabilities.json") + data, _ := os.ReadFile("./testdata/vcheck/vulnerabilities.json") var vulns []vulnJson if err := json.Unmarshal(data, &vulns); err != nil { t.Fatal(err) diff --git a/cmd/puppeth/genesis_test.go b/cmd/puppeth/genesis_test.go index aaa72d73cb..605c1070a8 100644 --- a/cmd/puppeth/genesis_test.go +++ b/cmd/puppeth/genesis_test.go @@ -19,7 +19,7 @@ package main import ( "bytes" "encoding/json" - "io/ioutil" + "os" "reflect" "strings" "testing" @@ -30,7 +30,7 @@ import ( // Tests the go-ethereum to Aleth chainspec conversion for the Stureby testnet. func TestAlethSturebyConverter(t *testing.T) { - blob, err := ioutil.ReadFile("testdata/stureby_geth.json") + blob, err := os.ReadFile("testdata/stureby_geth.json") if err != nil { t.Fatalf("could not read file: %v", err) } @@ -43,7 +43,7 @@ func TestAlethSturebyConverter(t *testing.T) { t.Fatalf("failed creating chainspec: %v", err) } - expBlob, err := ioutil.ReadFile("testdata/stureby_aleth.json") + expBlob, err := os.ReadFile("testdata/stureby_aleth.json") if err != nil { t.Fatalf("could not read file: %v", err) } @@ -69,7 +69,7 @@ func TestAlethSturebyConverter(t *testing.T) { // Tests the go-ethereum to Parity chainspec conversion for the Stureby testnet. func TestParitySturebyConverter(t *testing.T) { - blob, err := ioutil.ReadFile("testdata/stureby_geth.json") + blob, err := os.ReadFile("testdata/stureby_geth.json") if err != nil { t.Fatalf("could not read file: %v", err) } @@ -85,7 +85,7 @@ func TestParitySturebyConverter(t *testing.T) { if err != nil { t.Fatalf("failed encoding chainspec: %v", err) } - expBlob, err := ioutil.ReadFile("testdata/stureby_parity.json") + expBlob, err := os.ReadFile("testdata/stureby_parity.json") if err != nil { t.Fatalf("could not read file: %v", err) } diff --git a/cmd/puppeth/ssh.go b/cmd/puppeth/ssh.go index 039cb6cb45..95a36f3272 100644 --- a/cmd/puppeth/ssh.go +++ b/cmd/puppeth/ssh.go @@ -21,7 +21,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "net" "os" "os/user" @@ -96,7 +95,7 @@ func dial(server string, pubkey []byte) (*sshClient, error) { } if err != nil { path := filepath.Join(user.HomeDir, ".ssh", identity) - if buf, err := ioutil.ReadFile(path); err != nil { + if buf, err := os.ReadFile(path); err != nil { log.Warn("No SSH key, falling back to passwords", "path", path, "err", err) } else { key, err := ssh.ParsePrivateKey(buf) diff --git a/cmd/puppeth/wizard.go b/cmd/puppeth/wizard.go index c0edc54019..f7aafd4dd9 100644 --- a/cmd/puppeth/wizard.go +++ b/cmd/puppeth/wizard.go @@ -19,7 +19,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "math/big" "net" "net/url" @@ -65,7 +64,7 @@ func (c config) flush() { os.MkdirAll(filepath.Dir(c.path), 0755) out, _ := json.MarshalIndent(c, "", " ") - if err := ioutil.WriteFile(c.path, out, 0644); err != nil { + if err := os.WriteFile(c.path, out, 0644); err != nil { log.Warn("Failed to save puppeth configs", "file", c.path, "err", err) } } diff --git a/cmd/puppeth/wizard_genesis.go b/cmd/puppeth/wizard_genesis.go index ae5977b372..cb056ab133 100644 --- a/cmd/puppeth/wizard_genesis.go +++ b/cmd/puppeth/wizard_genesis.go @@ -21,7 +21,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "math/big" "math/rand" "net/http" @@ -263,7 +262,7 @@ func (w *wizard) manageGenesis() { // Export the native genesis spec used by puppeth and Geth gethJson := filepath.Join(folder, fmt.Sprintf("%s.json", w.network)) - if err := ioutil.WriteFile(gethJson, out, 0644); err != nil { + if err := os.WriteFile(gethJson, out, 0644); err != nil { log.Error("Failed to save genesis file", "err", err) return } @@ -305,7 +304,7 @@ func saveGenesis(folder, network, client string, spec interface{}) { path := filepath.Join(folder, fmt.Sprintf("%s-%s.json", network, client)) out, _ := json.MarshalIndent(spec, "", " ") - if err := ioutil.WriteFile(path, out, 0644); err != nil { + if err := os.WriteFile(path, out, 0644); err != nil { log.Error("Failed to save genesis file", "client", client, "err", err) return } diff --git a/cmd/puppeth/wizard_intro.go b/cmd/puppeth/wizard_intro.go index dd4b606c4a..adac943cc3 100644 --- a/cmd/puppeth/wizard_intro.go +++ b/cmd/puppeth/wizard_intro.go @@ -19,7 +19,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -73,7 +72,7 @@ func (w *wizard) run() { // Load initial configurations and connect to all live servers w.conf.path = filepath.Join(os.Getenv("HOME"), ".puppeth", w.network) - blob, err := ioutil.ReadFile(w.conf.path) + blob, err := os.ReadFile(w.conf.path) if err != nil { log.Warn("No previous configurations found", "path", w.conf.path) } else if err := json.Unmarshal(blob, &w.conf); err != nil { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 53466c695f..6f0901621d 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -21,7 +21,6 @@ import ( "crypto/ecdsa" "fmt" "io" - "io/ioutil" "math" "math/big" "os" @@ -1213,7 +1212,7 @@ func MakePasswordList(ctx *cli.Context) []string { if path == "" { return nil } - text, err := ioutil.ReadFile(path) + text, err := os.ReadFile(path) if err != nil { Fatalf("Failed to read password file: %v", err) } diff --git a/common/compiler/helpers.go b/common/compiler/helpers.go index 5ed640de8f..59d242af3d 100644 --- a/common/compiler/helpers.go +++ b/common/compiler/helpers.go @@ -19,7 +19,7 @@ package compiler import ( "bytes" - "io/ioutil" + "os" "regexp" ) @@ -55,7 +55,7 @@ type ContractInfo struct { func slurpFiles(files []string) (string, error) { var concat bytes.Buffer for _, file := range files { - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { return "", err } diff --git a/common/test_utils.go b/common/test_utils.go index a848642f77..7a175412f4 100644 --- a/common/test_utils.go +++ b/common/test_utils.go @@ -19,12 +19,12 @@ package common import ( "encoding/json" "fmt" - "io/ioutil" + "os" ) // LoadJSON reads the given file and unmarshals its content. func LoadJSON(file string, val interface{}) error { - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { return err } diff --git a/consensus/ethash/algorithm_test.go b/consensus/ethash/algorithm_test.go index 70e94f4905..88769d277c 100644 --- a/consensus/ethash/algorithm_test.go +++ b/consensus/ethash/algorithm_test.go @@ -19,7 +19,6 @@ package ethash import ( "bytes" "encoding/binary" - "io/ioutil" "math/big" "os" "reflect" @@ -700,7 +699,7 @@ func TestConcurrentDiskCacheGeneration(t *testing.T) { // Create a temp folder to generate the caches into // TODO: t.TempDir fails to remove the directory on Windows // \AppData\Local\Temp\1\TestConcurrentDiskCacheGeneration2382060137\001\cache-R23-1dca8a85e74aa763: Access is denied. - cachedir, err := ioutil.TempDir("", "") + cachedir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("Failed to create temporary cache dir: %v", err) } diff --git a/consensus/ethash/ethash_test.go b/consensus/ethash/ethash_test.go index 5e454fffb5..eb6bad9622 100644 --- a/consensus/ethash/ethash_test.go +++ b/consensus/ethash/ethash_test.go @@ -17,7 +17,6 @@ package ethash import ( - "io/ioutil" "math/big" "math/rand" "os" @@ -59,7 +58,7 @@ func TestTestMode(t *testing.T) { func TestCacheFileEvict(t *testing.T) { // TODO: t.TempDir fails to remove the directory on Windows // \AppData\Local\Temp\1\TestCacheFileEvict2179435125\001\cache-R23-0000000000000000: Access is denied. - tmpdir, err := ioutil.TempDir("", "ethash-test") + tmpdir, err := os.MkdirTemp("", "ethash-test") if err != nil { t.Fatal(err) } diff --git a/consensus/ethash/sealer_test.go b/consensus/ethash/sealer_test.go index c34e76aec2..e338f75290 100644 --- a/consensus/ethash/sealer_test.go +++ b/consensus/ethash/sealer_test.go @@ -18,7 +18,7 @@ package ethash import ( "encoding/json" - "io/ioutil" + "io" "math/big" "net/http" "net/http/httptest" @@ -37,7 +37,7 @@ func TestRemoteNotify(t *testing.T) { // Start a simple web server to capture notifications. sink := make(chan [3]string) server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) + blob, err := io.ReadAll(req.Body) if err != nil { t.Errorf("failed to read miner notification: %v", err) } @@ -80,7 +80,7 @@ func TestRemoteNotifyFull(t *testing.T) { // Start a simple web server to capture notifications. sink := make(chan map[string]interface{}) server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) + blob, err := io.ReadAll(req.Body) if err != nil { t.Errorf("failed to read miner notification: %v", err) } @@ -125,7 +125,7 @@ func TestRemoteMultiNotify(t *testing.T) { // Start a simple web server to capture notifications. sink := make(chan [3]string, 64) server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) + blob, err := io.ReadAll(req.Body) if err != nil { t.Errorf("failed to read miner notification: %v", err) } @@ -170,7 +170,7 @@ func TestRemoteMultiNotifyFull(t *testing.T) { // Start a simple web server to capture notifications. sink := make(chan map[string]interface{}, 64) server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - blob, err := ioutil.ReadAll(req.Body) + blob, err := io.ReadAll(req.Body) if err != nil { t.Errorf("failed to read miner notification: %v", err) } diff --git a/console/console.go b/console/console.go index f0f9b5dda0..2f61c1d7a4 100644 --- a/console/console.go +++ b/console/console.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/signal" "path/filepath" @@ -158,7 +157,7 @@ func (c *Console) init(preload []string) error { // Configure the input prompter for history and tab completion. if c.prompter != nil { - if content, err := ioutil.ReadFile(c.histPath); err != nil { + if content, err := os.ReadFile(c.histPath); err != nil { c.prompter.SetHistory(nil) } else { c.history = strings.Split(string(content), "\n") @@ -559,7 +558,7 @@ func (c *Console) Stop(graceful bool) error { } func (c *Console) writeHistory() error { - if err := ioutil.WriteFile(c.histPath, []byte(strings.Join(c.history, "\n")), 0600); err != nil { + if err := os.WriteFile(c.histPath, []byte(strings.Join(c.history, "\n")), 0600); err != nil { return err } return os.Chmod(c.histPath, 0600) // Force 0600, even if it was different previously diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index 2b80a1b84d..dbb13caa41 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -20,9 +20,9 @@ import ( "bytes" "encoding/hex" "fmt" - "io/ioutil" "math/big" "math/rand" + "os" "reflect" "testing" @@ -852,7 +852,7 @@ func TestDeriveLogFields(t *testing.T) { func BenchmarkDecodeRLPLogs(b *testing.B) { // Encoded receipts from block 0x14ee094309fbe8f70b65f45ebcc08fb33f126942d97464aad5eb91cfd1e2d269 - buf, err := ioutil.ReadFile("testdata/stored_receipts.bin") + buf, err := os.ReadFile("testdata/stored_receipts.bin") if err != nil { b.Fatal(err) } diff --git a/core/rawdb/freezer_meta_test.go b/core/rawdb/freezer_meta_test.go index 191744a754..3e20aad690 100644 --- a/core/rawdb/freezer_meta_test.go +++ b/core/rawdb/freezer_meta_test.go @@ -17,13 +17,12 @@ package rawdb import ( - "io/ioutil" "os" "testing" ) func TestReadWriteFreezerTableMeta(t *testing.T) { - f, err := ioutil.TempFile(os.TempDir(), "*") + f, err := os.CreateTemp(os.TempDir(), "*") if err != nil { t.Fatalf("Failed to create file %v", err) } @@ -44,7 +43,7 @@ func TestReadWriteFreezerTableMeta(t *testing.T) { } func TestInitializeFreezerTableMeta(t *testing.T) { - f, err := ioutil.TempFile(os.TempDir(), "*") + f, err := os.CreateTemp(os.TempDir(), "*") if err != nil { t.Fatalf("Failed to create file %v", err) } diff --git a/core/rawdb/freezer_utils.go b/core/rawdb/freezer_utils.go index 5695fc0fa8..e7cce2920d 100644 --- a/core/rawdb/freezer_utils.go +++ b/core/rawdb/freezer_utils.go @@ -18,7 +18,6 @@ package rawdb import ( "io" - "io/ioutil" "os" "path/filepath" ) @@ -30,7 +29,7 @@ import ( // It is perfectly valid to have destPath == srcPath. func copyFrom(srcPath, destPath string, offset uint64, before func(f *os.File) error) error { // Create a temp file in the same dir where we want it to wind up - f, err := ioutil.TempFile(filepath.Dir(destPath), "*") + f, err := os.CreateTemp(filepath.Dir(destPath), "*") if err != nil { return err } diff --git a/core/rawdb/freezer_utils_test.go b/core/rawdb/freezer_utils_test.go index de8087f9b9..cc300cb614 100644 --- a/core/rawdb/freezer_utils_test.go +++ b/core/rawdb/freezer_utils_test.go @@ -18,7 +18,6 @@ package rawdb import ( "bytes" - "io/ioutil" "os" "testing" ) @@ -44,7 +43,7 @@ func TestCopyFrom(t *testing.T) { {"foo", "bar", 8, true}, } for _, c := range cases { - ioutil.WriteFile(c.src, content, 0644) + os.WriteFile(c.src, content, 0644) if err := copyFrom(c.src, c.dest, c.offset, func(f *os.File) error { if !c.writePrefix { @@ -57,7 +56,7 @@ func TestCopyFrom(t *testing.T) { t.Fatalf("Failed to copy %v", err) } - blob, err := ioutil.ReadFile(c.dest) + blob, err := os.ReadFile(c.dest) if err != nil { os.Remove(c.src) os.Remove(c.dest) diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index a7af275835..dd2407470d 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -20,7 +20,6 @@ import ( "crypto/ecdsa" "errors" "fmt" - "io/ioutil" "math/big" "math/rand" "os" @@ -2243,7 +2242,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) { t.Parallel() // Create a temporary file for the journal - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") if err != nil { t.Fatalf("failed to create temporary journal: %v", err) } diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index aa8d2f1eb3..b22d999e6c 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -20,7 +20,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "testing" "time" @@ -334,7 +334,7 @@ func TestPrecompiledBLS12381MapG1Fail(t *testing.T) { testJsonFail("blsMapG func TestPrecompiledBLS12381MapG2Fail(t *testing.T) { testJsonFail("blsMapG2", "12", t) } func loadJson(name string) ([]precompiledTest, error) { - data, err := ioutil.ReadFile(fmt.Sprintf("testdata/precompiles/%v.json", name)) + data, err := os.ReadFile(fmt.Sprintf("testdata/precompiles/%v.json", name)) if err != nil { return nil, err } @@ -344,7 +344,7 @@ func loadJson(name string) ([]precompiledTest, error) { } func loadJsonFail(name string) ([]precompiledFailureTest, error) { - data, err := ioutil.ReadFile(fmt.Sprintf("testdata/precompiles/fail-%v.json", name)) + data, err := os.ReadFile(fmt.Sprintf("testdata/precompiles/fail-%v.json", name)) if err != nil { return nil, err } diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 36589a1269..8e6d6c92cf 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -20,8 +20,8 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "math/big" + "os" "testing" "github.com/ethereum/go-ethereum/common" @@ -260,7 +260,7 @@ func TestWriteExpectedValues(t *testing.T) { if err != nil { t.Fatal(err) } - _ = ioutil.WriteFile(fmt.Sprintf("testdata/testcases_%v.json", name), data, 0644) + _ = os.WriteFile(fmt.Sprintf("testdata/testcases_%v.json", name), data, 0644) if err != nil { t.Fatal(err) } @@ -270,7 +270,7 @@ func TestWriteExpectedValues(t *testing.T) { // TestJsonTestcases runs through all the testcases defined as json-files func TestJsonTestcases(t *testing.T) { for name := range twoOpMethods { - data, err := ioutil.ReadFile(fmt.Sprintf("testdata/testcases_%v.json", name)) + data, err := os.ReadFile(fmt.Sprintf("testdata/testcases_%v.json", name)) if err != nil { t.Fatal("Failed to read file", err) } diff --git a/crypto/crypto.go b/crypto/crypto.go index 40969a2895..45ea72747e 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -26,7 +26,6 @@ import ( "fmt" "hash" "io" - "io/ioutil" "math/big" "os" @@ -250,7 +249,7 @@ func checkKeyFileEnd(r *bufio.Reader) error { // restrictive permissions. The key data is saved hex-encoded. func SaveECDSA(file string, key *ecdsa.PrivateKey) error { k := hex.EncodeToString(FromECDSA(key)) - return ioutil.WriteFile(file, []byte(k), 0600) + return os.WriteFile(file, []byte(k), 0600) } // GenerateKey generates a new private key. diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index f9b0d3e834..da123cf980 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -20,7 +20,6 @@ import ( "bytes" "crypto/ecdsa" "encoding/hex" - "io/ioutil" "math/big" "os" "reflect" @@ -182,7 +181,7 @@ func TestLoadECDSA(t *testing.T) { } for _, test := range tests { - f, err := ioutil.TempFile("", "loadecdsa_test.*.txt") + f, err := os.CreateTemp("", "loadecdsa_test.*.txt") if err != nil { t.Fatal(err) } @@ -203,7 +202,7 @@ func TestLoadECDSA(t *testing.T) { } func TestSaveECDSA(t *testing.T) { - f, err := ioutil.TempFile("", "saveecdsa_test.*.txt") + f, err := os.CreateTemp("", "saveecdsa_test.*.txt") if err != nil { t.Fatal(err) } diff --git a/crypto/signify/signify.go b/crypto/signify/signify.go index e280f87268..eb029e5099 100644 --- a/crypto/signify/signify.go +++ b/crypto/signify/signify.go @@ -25,7 +25,7 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" + "os" "strings" "time" ) @@ -68,7 +68,7 @@ func SignFile(input string, output string, key string, untrustedComment string, trustedComment = fmt.Sprintf("timestamp:%d", time.Now().Unix()) } - filedata, err := ioutil.ReadFile(input) + filedata, err := os.ReadFile(input) if err != nil { return err } @@ -96,5 +96,5 @@ func SignFile(input string, output string, key string, untrustedComment string, fmt.Fprintln(out, base64.StdEncoding.EncodeToString(dataSig)) fmt.Fprintln(out, "trusted comment:", trustedComment) fmt.Fprintln(out, base64.StdEncoding.EncodeToString(commentSig)) - return ioutil.WriteFile(output, out.Bytes(), 0644) + return os.WriteFile(output, out.Bytes(), 0644) } diff --git a/crypto/signify/signify_fuzz.go b/crypto/signify/signify_fuzz.go index 2dc9b2102f..457af044d1 100644 --- a/crypto/signify/signify_fuzz.go +++ b/crypto/signify/signify_fuzz.go @@ -22,7 +22,6 @@ package signify import ( "bufio" "fmt" - "io/ioutil" "log" "os" "os/exec" @@ -35,7 +34,7 @@ func Fuzz(data []byte) int { if len(data) < 32 { return -1 } - tmpFile, err := ioutil.TempFile("", "") + tmpFile, err := os.CreateTemp("", "") if err != nil { panic(err) } @@ -76,7 +75,7 @@ func Fuzz(data []byte) int { // Write the public key into the file to pass it as // an argument to signify-openbsd - pubKeyFile, err := ioutil.TempFile("", "") + pubKeyFile, err := os.CreateTemp("", "") if err != nil { panic(err) } @@ -128,7 +127,7 @@ func getKey(fileS string) (string, error) { func createKeyPair() (string, string) { // Create key and put it in correct format - tmpKey, err := ioutil.TempFile("", "") + tmpKey, err := os.CreateTemp("", "") if err != nil { panic(err) } diff --git a/crypto/signify/signify_test.go b/crypto/signify/signify_test.go index 615d4e6527..ba85d2fc43 100644 --- a/crypto/signify/signify_test.go +++ b/crypto/signify/signify_test.go @@ -20,7 +20,6 @@ package signify import ( - "io/ioutil" "math/rand" "os" "testing" @@ -35,7 +34,7 @@ var ( ) func TestSignify(t *testing.T) { - tmpFile, err := ioutil.TempFile("", "") + tmpFile, err := os.CreateTemp("", "") if err != nil { t.Fatal(err) } @@ -79,7 +78,7 @@ func TestSignify(t *testing.T) { } func TestSignifyTrustedCommentTooManyLines(t *testing.T) { - tmpFile, err := ioutil.TempFile("", "") + tmpFile, err := os.CreateTemp("", "") if err != nil { t.Fatal(err) } @@ -104,7 +103,7 @@ func TestSignifyTrustedCommentTooManyLines(t *testing.T) { } func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) { - tmpFile, err := ioutil.TempFile("", "") + tmpFile, err := os.CreateTemp("", "") if err != nil { t.Fatal(err) } @@ -129,7 +128,7 @@ func TestSignifyTrustedCommentTooManyLinesLF(t *testing.T) { } func TestSignifyTrustedCommentEmpty(t *testing.T) { - tmpFile, err := ioutil.TempFile("", "") + tmpFile, err := os.CreateTemp("", "") if err != nil { t.Fatal(err) } diff --git a/eth/tracers/api.go b/eth/tracers/api.go index b7edc2236c..074f193e64 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -22,7 +22,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "runtime" "sync" @@ -463,7 +462,7 @@ func (api *API) TraceBlock(ctx context.Context, blob hexutil.Bytes, config *Trac // TraceBlockFromFile returns the structured logs created during the execution of // EVM and returns them as a JSON object. func (api *API) TraceBlockFromFile(ctx context.Context, file string, config *TraceConfig) ([]*txTraceResult, error) { - blob, err := ioutil.ReadFile(file) + blob, err := os.ReadFile(file) if err != nil { return nil, fmt.Errorf("could not read file: %v", err) } @@ -722,7 +721,7 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block if !canon { prefix = fmt.Sprintf("%valt-", prefix) } - dump, err = ioutil.TempFile(os.TempDir(), prefix) + dump, err = os.CreateTemp(os.TempDir(), prefix) if err != nil { return nil, err } diff --git a/eth/tracers/internal/tracetest/calltrace_test.go b/eth/tracers/internal/tracetest/calltrace_test.go index cf7c1e6c0d..b715d8ee9a 100644 --- a/eth/tracers/internal/tracetest/calltrace_test.go +++ b/eth/tracers/internal/tracetest/calltrace_test.go @@ -20,6 +20,7 @@ import ( "encoding/json" "io/ioutil" "math/big" + "os" "path/filepath" "reflect" "strings" @@ -152,7 +153,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) { tx = new(types.Transaction) ) // Call tracer test found, read if from disk - if blob, err := ioutil.ReadFile(filepath.Join("testdata", dirPath, file.Name())); err != nil { + if blob, err := os.ReadFile(filepath.Join("testdata", dirPath, file.Name())); err != nil { t.Fatalf("failed to read testcase: %v", err) } else if err := json.Unmarshal(blob, test); err != nil { t.Fatalf("failed to parse testcase: %v", err) @@ -250,7 +251,7 @@ func BenchmarkTracers(b *testing.B) { } file := file // capture range variable b.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(b *testing.B) { - blob, err := ioutil.ReadFile(filepath.Join("testdata", "call_tracer", file.Name())) + blob, err := os.ReadFile(filepath.Join("testdata", "call_tracer", file.Name())) if err != nil { b.Fatalf("failed to read testcase: %v", err) } diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index 828c057c3e..2768026b51 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -18,7 +18,7 @@ package graphql import ( "fmt" - "io/ioutil" + "io" "math/big" "net/http" "strings" @@ -146,7 +146,7 @@ func TestGraphQLBlockSerialization(t *testing.T) { if err != nil { t.Fatalf("could not post: %v", err) } - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("could not read from response body: %v", err) } @@ -182,7 +182,7 @@ func TestGraphQLBlockSerializationEIP2718(t *testing.T) { if err != nil { t.Fatalf("could not post: %v", err) } - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("could not read from response body: %v", err) } diff --git a/internal/build/download.go b/internal/build/download.go index efb223b327..903d0308df 100644 --- a/internal/build/download.go +++ b/internal/build/download.go @@ -22,7 +22,6 @@ import ( "encoding/hex" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -37,7 +36,7 @@ type ChecksumDB struct { // MustLoadChecksums loads a file containing checksums. func MustLoadChecksums(file string) *ChecksumDB { - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { log.Fatal("can't load checksum file: " + err.Error()) } diff --git a/internal/build/util.go b/internal/build/util.go index cd6db09d00..974d7001c3 100644 --- a/internal/build/util.go +++ b/internal/build/util.go @@ -77,7 +77,7 @@ func RunGit(args ...string) string { // readGitFile returns content of file in .git directory. func readGitFile(file string) string { - content, err := ioutil.ReadFile(path.Join(".git", file)) + content, err := os.ReadFile(path.Join(".git", file)) if err != nil { return "" } diff --git a/internal/cmdtest/test_cmd.go b/internal/cmdtest/test_cmd.go index d75db41e0d..b837c9c399 100644 --- a/internal/cmdtest/test_cmd.go +++ b/internal/cmdtest/test_cmd.go @@ -21,7 +21,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "os/exec" "regexp" @@ -184,7 +183,7 @@ func (tt *TestCmd) ExpectRegexp(regex string) (*regexp.Regexp, []string) { func (tt *TestCmd) ExpectExit() { var output []byte tt.withKillTimeout(func() { - output, _ = ioutil.ReadAll(tt.stdout) + output, _ = io.ReadAll(tt.stdout) }) tt.WaitExit() if tt.Cleanup != nil { diff --git a/internal/jsre/jsre.go b/internal/jsre/jsre.go index 24fedd8d28..4de80a9e90 100644 --- a/internal/jsre/jsre.go +++ b/internal/jsre/jsre.go @@ -23,8 +23,8 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/rand" + "os" "time" "github.com/dop251/goja" @@ -254,7 +254,7 @@ func (re *JSRE) Stop(waitForCallbacks bool) { // Exec(file) loads and runs the contents of a file // if a relative path is given, the jsre's assetPath is used func (re *JSRE) Exec(file string) error { - code, err := ioutil.ReadFile(common.AbsolutePath(re.assetPath, file)) + code, err := os.ReadFile(common.AbsolutePath(re.assetPath, file)) if err != nil { return err } @@ -320,7 +320,7 @@ func (re *JSRE) Compile(filename string, src string) (err error) { func (re *JSRE) loadScript(call Call) (goja.Value, error) { file := call.Argument(0).ToString().String() file = common.AbsolutePath(re.assetPath, file) - source, err := ioutil.ReadFile(file) + source, err := os.ReadFile(file) if err != nil { return nil, fmt.Errorf("Could not read file %s: %v", file, err) } diff --git a/internal/jsre/jsre_test.go b/internal/jsre/jsre_test.go index e6ecdeeda9..bb4ff5fa4f 100644 --- a/internal/jsre/jsre_test.go +++ b/internal/jsre/jsre_test.go @@ -17,7 +17,6 @@ package jsre import ( - "io/ioutil" "os" "path" "reflect" @@ -43,7 +42,7 @@ func (no *testNativeObjectBinding) TestMethod(call goja.FunctionCall) goja.Value func newWithTestJS(t *testing.T, testjs string) *JSRE { dir := t.TempDir() if testjs != "" { - if err := ioutil.WriteFile(path.Join(dir, "test.js"), []byte(testjs), os.ModePerm); err != nil { + if err := os.WriteFile(path.Join(dir, "test.js"), []byte(testjs), os.ModePerm); err != nil { t.Fatal("cannot create test.js:", err) } } diff --git a/internal/utesting/utesting.go b/internal/utesting/utesting.go index ef05a90e4c..ee99794c64 100644 --- a/internal/utesting/utesting.go +++ b/internal/utesting/utesting.go @@ -25,7 +25,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "regexp" "runtime" "sync" @@ -65,7 +64,7 @@ func MatchTests(tests []Test, expr string) []Test { // If the report writer is non-nil, a test report is written to it in real time. func RunTests(tests []Test, report io.Writer) []Result { if report == nil { - report = ioutil.Discard + report = io.Discard } results := run(tests, newConsoleOutput(report)) fails := CountFailures(results) diff --git a/les/api_test.go b/les/api_test.go index 6a19b0fe4f..ea6870e356 100644 --- a/les/api_test.go +++ b/les/api_test.go @@ -20,7 +20,6 @@ import ( "context" "errors" "flag" - "io/ioutil" "math/rand" "os" "sync" @@ -423,7 +422,7 @@ func NewAdapter(adapterType string, services adapters.LifecycleConstructors) (ad // case "socket": // adapter = adapters.NewSocketAdapter(services) case "exec": - baseDir, err0 := ioutil.TempDir("", "les-test") + baseDir, err0 := os.MkdirTemp("", "les-test") if err0 != nil { return nil, teardown, err0 } diff --git a/metrics/librato/client.go b/metrics/librato/client.go index f7aed3e4ef..eebe20521b 100644 --- a/metrics/librato/client.go +++ b/metrics/librato/client.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" ) @@ -93,7 +93,7 @@ func (c *LibratoClient) PostMetrics(batch Batch) (err error) { if resp.StatusCode != http.StatusOK { var body []byte - if body, err = ioutil.ReadAll(resp.Body); err != nil { + if body, err = io.ReadAll(resp.Body); err != nil { body = []byte(fmt.Sprintf("(could not fetch response body for error: %s)", err)) } err = fmt.Errorf("unable to post to Librato: %d %s %s", resp.StatusCode, resp.Status, string(body)) diff --git a/metrics/metrics_test.go b/metrics/metrics_test.go index df36da0ade..029c99870e 100644 --- a/metrics/metrics_test.go +++ b/metrics/metrics_test.go @@ -2,7 +2,7 @@ package metrics import ( "fmt" - "io/ioutil" + "io" "log" "sync" "testing" @@ -13,7 +13,7 @@ const FANOUT = 128 // Stop the compiler from complaining during debugging. var ( - _ = ioutil.Discard + _ = io.Discard _ = log.LstdFlags ) @@ -78,7 +78,7 @@ func BenchmarkMetrics(b *testing.B) { //log.Println("done Write") return default: - WriteOnce(r, ioutil.Discard) + WriteOnce(r, io.Discard) } } }() diff --git a/miner/stress/1559/main.go b/miner/stress/1559/main.go index 7c6134b3f9..9c1ab0f4a1 100644 --- a/miner/stress/1559/main.go +++ b/miner/stress/1559/main.go @@ -19,7 +19,6 @@ package main import ( "crypto/ecdsa" - "io/ioutil" "math/big" "math/rand" "os" @@ -222,7 +221,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis { func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { // Define the basic configurations for the Ethereum node - datadir, _ := ioutil.TempDir("", "") + datadir, _ := os.MkdirTemp("", "") config := &node.Config{ Name: "geth", diff --git a/miner/stress/beacon/main.go b/miner/stress/beacon/main.go index ccb7279b04..3f751049b8 100644 --- a/miner/stress/beacon/main.go +++ b/miner/stress/beacon/main.go @@ -20,7 +20,6 @@ package main import ( "crypto/ecdsa" "errors" - "io/ioutil" "math/big" "math/rand" "os" @@ -461,7 +460,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis { func makeFullNode(genesis *core.Genesis) (*node.Node, *eth.Ethereum, *ethcatalyst.ConsensusAPI, error) { // Define the basic configurations for the Ethereum node - datadir, _ := ioutil.TempDir("", "") + datadir, _ := os.MkdirTemp("", "") config := &node.Config{ Name: "geth", @@ -512,7 +511,7 @@ func makeFullNode(genesis *core.Genesis) (*node.Node, *eth.Ethereum, *ethcatalys func makeLightNode(genesis *core.Genesis) (*node.Node, *les.LightEthereum, *lescatalyst.ConsensusAPI, error) { // Define the basic configurations for the Ethereum node - datadir, _ := ioutil.TempDir("", "") + datadir, _ := os.MkdirTemp("", "") config := &node.Config{ Name: "geth", diff --git a/miner/stress/clique/main.go b/miner/stress/clique/main.go index f30da55dff..070a6ed60e 100644 --- a/miner/stress/clique/main.go +++ b/miner/stress/clique/main.go @@ -20,7 +20,6 @@ package main import ( "bytes" "crypto/ecdsa" - "io/ioutil" "math/big" "math/rand" "os" @@ -183,7 +182,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { // Define the basic configurations for the Ethereum node - datadir, _ := ioutil.TempDir("", "") + datadir, _ := os.MkdirTemp("", "") config := &node.Config{ Name: "geth", diff --git a/miner/stress/ethash/main.go b/miner/stress/ethash/main.go index bd9111ee35..56a6e58173 100644 --- a/miner/stress/ethash/main.go +++ b/miner/stress/ethash/main.go @@ -19,7 +19,6 @@ package main import ( "crypto/ecdsa" - "io/ioutil" "math/big" "math/rand" "os" @@ -152,7 +151,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey) *core.Genesis { func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { // Define the basic configurations for the Ethereum node - datadir, _ := ioutil.TempDir("", "") + datadir, _ := os.MkdirTemp("", "") config := &node.Config{ Name: "geth", diff --git a/mobile/android_test.go b/mobile/android_test.go index 43caa87e58..2ddf5d9d91 100644 --- a/mobile/android_test.go +++ b/mobile/android_test.go @@ -17,7 +17,6 @@ package geth import ( - "io/ioutil" "os" "os/exec" "path/filepath" @@ -210,14 +209,14 @@ func TestAndroid(t *testing.T) { } cp.CopyFile(filepath.Join("libs", "geth.aar"), "geth.aar") - if err = ioutil.WriteFile(filepath.Join("src", "androidTest", "java", "org", "ethereum", "gethtest", "AndroidTest.java"), []byte(androidTestClass), os.ModePerm); err != nil { + if err = os.WriteFile(filepath.Join("src", "androidTest", "java", "org", "ethereum", "gethtest", "AndroidTest.java"), []byte(androidTestClass), os.ModePerm); err != nil { t.Fatalf("failed to write Android test class: %v", err) } // Finish creating the project and run the tests via gradle - if err = ioutil.WriteFile(filepath.Join("src", "main", "AndroidManifest.xml"), []byte(androidManifest), os.ModePerm); err != nil { + if err = os.WriteFile(filepath.Join("src", "main", "AndroidManifest.xml"), []byte(androidManifest), os.ModePerm); err != nil { t.Fatalf("failed to write Android manifest: %v", err) } - if err = ioutil.WriteFile("build.gradle", []byte(gradleConfig), os.ModePerm); err != nil { + if err = os.WriteFile("build.gradle", []byte(gradleConfig), os.ModePerm); err != nil { t.Fatalf("failed to write gradle build file: %v", err) } if output, err := exec.Command("gradle", "connectedAndroidTest").CombinedOutput(); err != nil { diff --git a/node/config.go b/node/config.go index 853190c95f..2047299fb5 100644 --- a/node/config.go +++ b/node/config.go @@ -19,7 +19,6 @@ package node import ( "crypto/ecdsa" "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -470,7 +469,7 @@ func getKeyStoreDir(conf *Config) (string, bool, error) { isEphemeral := false if keydir == "" { // There is no datadir. - keydir, err = ioutil.TempDir("", "go-ethereum-keystore") + keydir, err = os.MkdirTemp("", "go-ethereum-keystore") isEphemeral = true } diff --git a/node/config_test.go b/node/config_test.go index 5d70061691..d9f812ec4c 100644 --- a/node/config_test.go +++ b/node/config_test.go @@ -18,7 +18,6 @@ package node import ( "bytes" - "io/ioutil" "os" "path/filepath" "runtime" @@ -54,7 +53,7 @@ func TestDatadirCreation(t *testing.T) { t.Fatalf("freshly created datadir not accessible: %v", err) } // Verify that an impossible datadir fails creation - file, err := ioutil.TempFile("", "") + file, err := os.CreateTemp("", "") if err != nil { t.Fatalf("failed to create temporary file: %v", err) } @@ -132,7 +131,7 @@ func TestNodeKeyPersistency(t *testing.T) { if _, err = crypto.LoadECDSA(keyfile); err != nil { t.Fatalf("failed to load freshly persisted node key: %v", err) } - blob1, err := ioutil.ReadFile(keyfile) + blob1, err := os.ReadFile(keyfile) if err != nil { t.Fatalf("failed to read freshly persisted node key: %v", err) } @@ -140,7 +139,7 @@ func TestNodeKeyPersistency(t *testing.T) { // Configure a new node and ensure the previously persisted key is loaded config = &Config{Name: "unit-test", DataDir: dir} config.NodeKey() - blob2, err := ioutil.ReadFile(filepath.Join(keyfile)) + blob2, err := os.ReadFile(filepath.Join(keyfile)) if err != nil { t.Fatalf("failed to read previously persisted node key: %v", err) } diff --git a/node/rpcstack.go b/node/rpcstack.go index d9c41cca57..2ee47d250a 100644 --- a/node/rpcstack.go +++ b/node/rpcstack.go @@ -21,7 +21,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "net" "net/http" "sort" @@ -444,7 +443,7 @@ func (h *virtualHostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var gzPool = sync.Pool{ New: func() interface{} { - w := gzip.NewWriter(ioutil.Discard) + w := gzip.NewWriter(io.Discard) return w }, } diff --git a/p2p/discover/v5wire/encoding_test.go b/p2p/discover/v5wire/encoding_test.go index 355a8f6913..0fa80298fe 100644 --- a/p2p/discover/v5wire/encoding_test.go +++ b/p2p/discover/v5wire/encoding_test.go @@ -23,7 +23,6 @@ import ( "errors" "flag" "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -580,7 +579,7 @@ func (n *handshakeTestNode) id() enode.ID { // hexFile reads the given file and decodes the hex data contained in it. // Whitespace and any lines beginning with the # character are ignored. func hexFile(file string) []byte { - fileContent, err := ioutil.ReadFile(file) + fileContent, err := os.ReadFile(file) if err != nil { panic(err) } diff --git a/p2p/message.go b/p2p/message.go index bd048138c3..7cbe0f1dc8 100644 --- a/p2p/message.go +++ b/p2p/message.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "sync/atomic" "time" @@ -66,7 +65,7 @@ func (msg Msg) String() string { // Discard reads any remaining payload data into a black hole. func (msg Msg) Discard() error { - _, err := io.Copy(ioutil.Discard, msg.Payload) + _, err := io.Copy(io.Discard, msg.Payload) return err } @@ -245,7 +244,7 @@ func ExpectMsg(r MsgReader, code uint64, content interface{}) error { if int(msg.Size) != len(contentEnc) { return fmt.Errorf("message size mismatch: got %d, want %d", msg.Size, len(contentEnc)) } - actualContent, err := ioutil.ReadAll(msg.Payload) + actualContent, err := io.ReadAll(msg.Payload) if err != nil { return err } diff --git a/p2p/simulations/examples/ping-pong.go b/p2p/simulations/examples/ping-pong.go index 0cddd9b505..2f4c560548 100644 --- a/p2p/simulations/examples/ping-pong.go +++ b/p2p/simulations/examples/ping-pong.go @@ -19,7 +19,7 @@ package main import ( "flag" "fmt" - "io/ioutil" + "io" "net/http" "os" "sync/atomic" @@ -63,7 +63,7 @@ func main() { adapter = adapters.NewSimAdapter(services) case "exec": - tmpdir, err := ioutil.TempDir("", "p2p-example") + tmpdir, err := os.MkdirTemp("", "p2p-example") if err != nil { log.Crit("error creating temp dir", "err", err) } @@ -156,7 +156,7 @@ func (p *pingPongService) Run(peer *p2p.Peer, rw p2p.MsgReadWriter) error { errC <- err return } - payload, err := ioutil.ReadAll(msg.Payload) + payload, err := io.ReadAll(msg.Payload) if err != nil { errC <- err return diff --git a/p2p/simulations/http.go b/p2p/simulations/http.go index 45c12f7433..341ff8718b 100644 --- a/p2p/simulations/http.go +++ b/p2p/simulations/http.go @@ -24,7 +24,6 @@ import ( "fmt" "html" "io" - "io/ioutil" "net/http" "strconv" "strings" @@ -112,7 +111,7 @@ func (c *Client) SubscribeNetwork(events chan *Event, opts SubscribeOpts) (event return nil, err } if res.StatusCode != http.StatusOK { - response, _ := ioutil.ReadAll(res.Body) + response, _ := io.ReadAll(res.Body) res.Body.Close() return nil, fmt.Errorf("unexpected HTTP status: %s: %s", res.Status, response) } @@ -252,7 +251,7 @@ func (c *Client) Send(method, path string, in, out interface{}) error { } defer res.Body.Close() if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated { - response, _ := ioutil.ReadAll(res.Body) + response, _ := io.ReadAll(res.Body) return fmt.Errorf("unexpected HTTP status: %s: %s", res.Status, response) } if out != nil { diff --git a/rlp/encode_test.go b/rlp/encode_test.go index 1d715e3776..78392906b5 100644 --- a/rlp/encode_test.go +++ b/rlp/encode_test.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "math/big" "runtime" "sync" @@ -420,7 +419,7 @@ func TestEncodeToReader(t *testing.T) { if err != nil { return nil, err } - return ioutil.ReadAll(r) + return io.ReadAll(r) }) } @@ -461,7 +460,7 @@ func TestEncodeToReaderReturnToPool(t *testing.T) { go func() { for i := 0; i < 1000; i++ { _, r, _ := EncodeToReader("foo") - ioutil.ReadAll(r) + io.ReadAll(r) r.Read(buf) r.Read(buf) r.Read(buf) diff --git a/rlp/rlpgen/gen_test.go b/rlp/rlpgen/gen_test.go index 9940db188d..ff7ccdbedd 100644 --- a/rlp/rlpgen/gen_test.go +++ b/rlp/rlpgen/gen_test.go @@ -8,7 +8,6 @@ import ( "go/parser" "go/token" "go/types" - "io/ioutil" "os" "path/filepath" "testing" @@ -51,11 +50,11 @@ func TestOutput(t *testing.T) { // Set this environment variable to regenerate the test outputs. if os.Getenv("WRITE_TEST_FILES") != "" { - ioutil.WriteFile(outputFile, output, 0644) + os.WriteFile(outputFile, output, 0644) } // Check if output matches. - wantOutput, err := ioutil.ReadFile(outputFile) + wantOutput, err := os.ReadFile(outputFile) if err != nil { t.Fatal("error loading expected test output:", err) } @@ -68,7 +67,7 @@ func TestOutput(t *testing.T) { func loadTestSource(file string, typeName string) (*buildContext, *types.Named, error) { // Load the test input. - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { return nil, nil, err } diff --git a/rlp/rlpgen/main.go b/rlp/rlpgen/main.go index 5b240bfd85..37d585888a 100644 --- a/rlp/rlpgen/main.go +++ b/rlp/rlpgen/main.go @@ -22,7 +22,6 @@ import ( "flag" "fmt" "go/types" - "io/ioutil" "os" "golang.org/x/tools/go/packages" @@ -52,7 +51,7 @@ func main() { } if *output == "-" { os.Stdout.Write(code) - } else if err := ioutil.WriteFile(*output, code, 0644); err != nil { + } else if err := os.WriteFile(*output, code, 0644); err != nil { fatal(err) } } diff --git a/rpc/http.go b/rpc/http.go index 18404c060a..9f44649573 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "mime" "net/http" "net/url" @@ -176,12 +175,12 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos if err != nil { return nil, err } - req, err := http.NewRequestWithContext(ctx, "POST", hc.url, ioutil.NopCloser(bytes.NewReader(body))) + req, err := http.NewRequestWithContext(ctx, "POST", hc.url, io.NopCloser(bytes.NewReader(body))) if err != nil { return nil, err } req.ContentLength = int64(len(body)) - req.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewReader(body)), nil } + req.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(body)), nil } // set headers hc.mu.Lock() diff --git a/rpc/server_test.go b/rpc/server_test.go index e67893710d..46fa06d952 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -22,6 +22,7 @@ import ( "io" "io/ioutil" "net" + "os" "path/filepath" "strings" "testing" @@ -70,7 +71,7 @@ func TestServer(t *testing.T) { func runTestScript(t *testing.T, file string) { server := newTestServer() - content, err := ioutil.ReadFile(file) + content, err := os.ReadFile(file) if err != nil { t.Fatal(err) } diff --git a/signer/core/signed_data_test.go b/signer/core/signed_data_test.go index fbc2903d9e..7c518b3c94 100644 --- a/signer/core/signed_data_test.go +++ b/signer/core/signed_data_test.go @@ -22,6 +22,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "os" "path" "strings" "testing" @@ -362,7 +363,7 @@ func TestJsonFiles(t *testing.T) { continue } expectedFailure := strings.HasPrefix(fInfo.Name(), "expfail") - data, err := ioutil.ReadFile(path.Join("testdata", fInfo.Name())) + data, err := os.ReadFile(path.Join("testdata", fInfo.Name())) if err != nil { t.Errorf("Failed to read file %v: %v", fInfo.Name(), err) continue @@ -394,7 +395,7 @@ func TestFuzzerFiles(t *testing.T) { } verbose := false for i, fInfo := range testfiles { - data, err := ioutil.ReadFile(path.Join(corpusdir, fInfo.Name())) + data, err := os.ReadFile(path.Join(corpusdir, fInfo.Name())) if err != nil { t.Errorf("Failed to read file %v: %v", fInfo.Name(), err) continue diff --git a/signer/core/uiapi.go b/signer/core/uiapi.go index 3a0327d869..59466d8fa0 100644 --- a/signer/core/uiapi.go +++ b/signer/core/uiapi.go @@ -21,8 +21,8 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math/big" + "os" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -175,7 +175,7 @@ func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.Raw if wallet.URL().Scheme != keystore.KeyStoreScheme { return nil, fmt.Errorf("account is not a keystore-account") } - return ioutil.ReadFile(wallet.URL().Path) + return os.ReadFile(wallet.URL().Path) } // Import tries to import the given keyJSON in the local keystore. The keyJSON data is expected to be diff --git a/signer/fourbyte/fourbyte.go b/signer/fourbyte/fourbyte.go index 090344523e..f2256a28f0 100644 --- a/signer/fourbyte/fourbyte.go +++ b/signer/fourbyte/fourbyte.go @@ -22,7 +22,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io/ioutil" "os" ) @@ -83,7 +82,7 @@ func NewWithFile(path string) (*Database, error) { // Custom file may not exist. Will be created during save, if needed. if _, err := os.Stat(path); err == nil { var blob []byte - if blob, err = ioutil.ReadFile(path); err != nil { + if blob, err = os.ReadFile(path); err != nil { return nil, err } if err := json.Unmarshal(blob, &db.custom); err != nil { @@ -137,5 +136,5 @@ func (db *Database) AddSelector(selector string, data []byte) error { if err != nil { return err } - return ioutil.WriteFile(db.customPath, blob, 0600) + return os.WriteFile(db.customPath, blob, 0600) } diff --git a/signer/storage/aes_gcm_storage.go b/signer/storage/aes_gcm_storage.go index 1dad34a3eb..f09bfa7d4f 100644 --- a/signer/storage/aes_gcm_storage.go +++ b/signer/storage/aes_gcm_storage.go @@ -22,7 +22,6 @@ import ( "crypto/rand" "encoding/json" "io" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/log" @@ -114,7 +113,7 @@ func (s *AESEncryptedStorage) Del(key string) { // readEncryptedStorage reads the file with encrypted creds func (s *AESEncryptedStorage) readEncryptedStorage() (map[string]storedCredential, error) { creds := make(map[string]storedCredential) - raw, err := ioutil.ReadFile(s.filename) + raw, err := os.ReadFile(s.filename) if err != nil { if os.IsNotExist(err) { @@ -136,7 +135,7 @@ func (s *AESEncryptedStorage) writeEncryptedStorage(creds map[string]storedCrede if err != nil { return err } - if err = ioutil.WriteFile(s.filename, raw, 0600); err != nil { + if err = os.WriteFile(s.filename, raw, 0600); err != nil { return err } return nil diff --git a/signer/storage/aes_gcm_storage_test.go b/signer/storage/aes_gcm_storage_test.go index abb97de9f7..a2a95d9dee 100644 --- a/signer/storage/aes_gcm_storage_test.go +++ b/signer/storage/aes_gcm_storage_test.go @@ -20,7 +20,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "os" "testing" "github.com/ethereum/go-ethereum/common" @@ -125,7 +125,7 @@ func TestSwappedKeys(t *testing.T) { // Now make a modified copy creds := make(map[string]storedCredential) - raw, err := ioutil.ReadFile(s1.filename) + raw, err := os.ReadFile(s1.filename) if err != nil { t.Fatal(err) } @@ -140,7 +140,7 @@ func TestSwappedKeys(t *testing.T) { if err != nil { t.Fatal(err) } - if err = ioutil.WriteFile(s1.filename, raw, 0600); err != nil { + if err = os.WriteFile(s1.filename, raw, 0600); err != nil { t.Fatal(err) } } diff --git a/tests/fuzzers/abi/abifuzzer_test.go b/tests/fuzzers/abi/abifuzzer_test.go index 423a3cd232..c66399e1b7 100644 --- a/tests/fuzzers/abi/abifuzzer_test.go +++ b/tests/fuzzers/abi/abifuzzer_test.go @@ -36,7 +36,7 @@ func TestGenerateCorpus(t *testing.T) { data := common.FromHex(corpusHex) checksum := sha1.Sum(data) outf := fmt.Sprintf("corpus/%x", checksum) - if err := ioutil.WriteFile(outf, data, 0777); err != nil { + if err := os.WriteFile(outf, data, 0777); err != nil { panic(err) } */ diff --git a/tests/fuzzers/difficulty/debug/main.go b/tests/fuzzers/difficulty/debug/main.go index 23516b3a0d..e982eef09a 100644 --- a/tests/fuzzers/difficulty/debug/main.go +++ b/tests/fuzzers/difficulty/debug/main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/tests/fuzzers/difficulty" @@ -14,7 +13,7 @@ func main() { os.Exit(1) } crasher := os.Args[1] - data, err := ioutil.ReadFile(crasher) + data, err := os.ReadFile(crasher) if err != nil { fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) os.Exit(1) diff --git a/tests/fuzzers/les/debug/main.go b/tests/fuzzers/les/debug/main.go index 09e087d4c8..77a6127030 100644 --- a/tests/fuzzers/les/debug/main.go +++ b/tests/fuzzers/les/debug/main.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/tests/fuzzers/les" @@ -32,7 +31,7 @@ func main() { os.Exit(1) } crasher := os.Args[1] - data, err := ioutil.ReadFile(crasher) + data, err := os.ReadFile(crasher) if err != nil { fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) os.Exit(1) diff --git a/tests/fuzzers/rangeproof/debug/main.go b/tests/fuzzers/rangeproof/debug/main.go index a81c69fea5..d4cab8ec46 100644 --- a/tests/fuzzers/rangeproof/debug/main.go +++ b/tests/fuzzers/rangeproof/debug/main.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/tests/fuzzers/rangeproof" @@ -32,7 +31,7 @@ func main() { os.Exit(1) } crasher := os.Args[1] - data, err := ioutil.ReadFile(crasher) + data, err := os.ReadFile(crasher) if err != nil { fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) os.Exit(1) diff --git a/tests/fuzzers/snap/debug/main.go b/tests/fuzzers/snap/debug/main.go index d0d1b49307..aad6346f64 100644 --- a/tests/fuzzers/snap/debug/main.go +++ b/tests/fuzzers/snap/debug/main.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/tests/fuzzers/snap" @@ -30,7 +29,7 @@ func main() { os.Exit(1) } crasher := os.Args[1] - data, err := ioutil.ReadFile(crasher) + data, err := os.ReadFile(crasher) if err != nil { fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) os.Exit(1) diff --git a/tests/fuzzers/stacktrie/debug/main.go b/tests/fuzzers/stacktrie/debug/main.go index 1ec28a8ef1..042992e9e2 100644 --- a/tests/fuzzers/stacktrie/debug/main.go +++ b/tests/fuzzers/stacktrie/debug/main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/tests/fuzzers/stacktrie" @@ -14,7 +13,7 @@ func main() { os.Exit(1) } crasher := os.Args[1] - data, err := ioutil.ReadFile(crasher) + data, err := os.ReadFile(crasher) if err != nil { fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) os.Exit(1) diff --git a/tests/fuzzers/vflux/debug/main.go b/tests/fuzzers/vflux/debug/main.go index 1d4a5ff19c..e6cec04606 100644 --- a/tests/fuzzers/vflux/debug/main.go +++ b/tests/fuzzers/vflux/debug/main.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "os" "github.com/ethereum/go-ethereum/log" @@ -35,7 +34,7 @@ func main() { os.Exit(1) } crasher := os.Args[1] - data, err := ioutil.ReadFile(crasher) + data, err := os.ReadFile(crasher) if err != nil { fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) os.Exit(1) diff --git a/tests/init_test.go b/tests/init_test.go index 7e2f3ff7f5..218634966d 100644 --- a/tests/init_test.go +++ b/tests/init_test.go @@ -20,7 +20,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "reflect" @@ -45,7 +44,7 @@ var ( ) func readJSON(reader io.Reader, value interface{}) error { - data, err := ioutil.ReadAll(reader) + data, err := io.ReadAll(reader) if err != nil { return fmt.Errorf("error reading JSON file: %v", err) }