Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil (#2717)
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
  • Loading branch information
testwill authored Oct 16, 2023
1 parent b617c97 commit 39d2f29
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions common/buf/multi_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/rand"
"io"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -120,7 +119,7 @@ func TestMultiBufferReadAllToByte(t *testing.T) {
common.Must(err)
f.Close()

cnt, err := ioutil.ReadFile(dat)
cnt, err := os.ReadFile(dat)
common.Must(err)

if d := cmp.Diff(buf2, cnt); d != "" {
Expand Down
4 changes: 2 additions & 2 deletions common/cmdarg/arg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmdarg
import (
"bytes"
"io"
"io/ioutil"
"os"
)

// LoadArg loads one arg, maybe an remote url, or local file path
Expand All @@ -18,7 +18,7 @@ func LoadArg(arg string) (out io.Reader, err error) {

// LoadArgToBytes loads one arg to []byte, maybe an remote url, or local file path
func LoadArgToBytes(arg string) (out []byte, err error) {
out, err = ioutil.ReadFile(arg)
out, err = os.ReadFile(arg)
if err != nil {
return
}
Expand Down
3 changes: 1 addition & 2 deletions common/log/logger_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package log_test

import (
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -13,7 +12,7 @@ import (
)

func TestFileLogger(t *testing.T) {
f, err := ioutil.TempFile("", "vtest")
f, err := os.CreateTemp("", "vtest")
common.Must(err)
path := f.Name()
common.Must(f.Close())
Expand Down
6 changes: 3 additions & 3 deletions infra/conf/geodata/memconservative/cache.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package memconservative

import (
"io/ioutil"
"os"
"strings"

"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -53,7 +53,7 @@ func (g GeoIPCache) Unmarshal(filename, code string) (*routercommon.GeoIP, error
case errFailedToReadBytes, errFailedToReadExpectedLenBytes,
errInvalidGeodataFile, errInvalidGeodataVarintLength:
newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method")
geoipBytes, err = ioutil.ReadFile(asset)
geoipBytes, err = os.ReadFile(asset)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func (g GeoSiteCache) Unmarshal(filename, code string) (*routercommon.GeoSite, e
case errFailedToReadBytes, errFailedToReadExpectedLenBytes,
errInvalidGeodataFile, errInvalidGeodataVarintLength:
newError("failed to decode geoip file: ", filename, ", fallback to the original ReadFile method")
geositeBytes, err = ioutil.ReadFile(asset)
geositeBytes, err = os.ReadFile(asset)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions infra/vprotogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"go/build"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -48,7 +47,7 @@ func GetRuntimeEnv(key string) (string, error) {
}
var data []byte
var runtimeEnv string
data, readErr := ioutil.ReadFile(file)
data, readErr := os.ReadFile(file)
if readErr != nil {
return "", readErr
}
Expand Down
3 changes: 1 addition & 2 deletions main/commands/helpers/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package helpers

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)

// ReadDir finds files according to extensions in the dir
func ReadDir(dir string, extensions []string) ([]string, error) {
confs, err := ioutil.ReadDir(dir)
confs, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions main/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package commands

import (
"fmt"
"io/ioutil"
"log"
"os"
"os/signal"
Expand Down Expand Up @@ -113,7 +112,7 @@ func dirExists(file string) bool {
}

func readConfDir(dirPath string, extension []string) cmdarg.Arg {
confs, err := ioutil.ReadDir(dirPath)
confs, err := os.ReadDir(dirPath)
if err != nil {
base.Fatalf("failed to read dir %s: %s", dirPath, err)
}
Expand Down

0 comments on commit 39d2f29

Please sign in to comment.