Skip to content

Commit 627ebc4

Browse files
committed
cleanup: remove ioutil
Signed-off-by: xin.li <[email protected]>
1 parent c34a5e7 commit 627ebc4

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

config_dbtester.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package dbtester
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
19+
"os"
2020
"path/filepath"
2121
"strings"
2222

@@ -57,7 +57,7 @@ type Config struct {
5757

5858
// ReadConfig reads control configuration file.
5959
func ReadConfig(fpath string, analyze bool) (*Config, error) {
60-
bts, err := ioutil.ReadFile(fpath)
60+
bts, err := os.ReadFile(fpath)
6161
if err != nil {
6262
return nil, err
6363
}
@@ -279,7 +279,7 @@ func ReadConfig(fpath string, analyze bool) (*Config, error) {
279279
}
280280

281281
if cfg.ConfigClientMachineInitial.GoogleCloudStorageKeyPath != "" && !analyze {
282-
bts, err = ioutil.ReadFile(cfg.ConfigClientMachineInitial.GoogleCloudStorageKeyPath)
282+
bts, err = os.ReadFile(cfg.ConfigClientMachineInitial.GoogleCloudStorageKeyPath)
283283
if err != nil {
284284
return nil, err
285285
}

pkg/fileinspect/fileinspect_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package fileinspect
1717
import (
1818
"bytes"
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"testing"
@@ -45,7 +44,7 @@ func writeData(fpath string, data []byte) (n int, err error) {
4544
}
4645

4746
func createData() (dir string, n int64, err error) {
48-
dir, err = ioutil.TempDir(os.TempDir(), "fileinspect-write-test")
47+
dir, err = os.MkdirTemp(os.TempDir(), "fileinspect-write-test")
4948
if err != nil {
5049
return
5150
}

pkg/remotestorage/example/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
package main
1616

1717
import (
18-
"io/ioutil"
1918
"log"
19+
"os"
2020

2121
"github.com/etcd-io/dbtester/pkg/remotestorage"
2222

2323
"go.uber.org/zap"
2424
)
2525

2626
func main() {
27-
kbs, err := ioutil.ReadFile("key.json")
27+
kbs, err := os.ReadFile("key.json")
2828
if err != nil {
2929
log.Fatal(err)
3030
}
@@ -37,7 +37,7 @@ func main() {
3737
}
3838

3939
// upload directories
40-
// kbs, err := ioutil.ReadFile("key.json")
40+
// kbs, err := os.ReadFile("key.json")
4141
// if err != nil {
4242
// log.Fatal(err)
4343
// }

pkg/remotestorage/uploader.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package remotestorage
1717
import (
1818
"context"
1919
"fmt"
20-
"io/ioutil"
20+
"os"
2121
"path/filepath"
2222
"strings"
2323

@@ -91,9 +91,9 @@ func (g *GoogleCloudStorage) UploadFile(bucket, src, dst string, opts ...OpOptio
9191
}
9292

9393
g.lg.Info("uploading", zap.String("source", src), zap.String("destination", dst))
94-
bts, err := ioutil.ReadFile(src)
94+
bts, err := os.ReadFile(src)
9595
if err != nil {
96-
return fmt.Errorf("ioutil.ReadFile(%s) %v", src, err)
96+
return fmt.Errorf("os.ReadFile(%s) %v", src, err)
9797
}
9898
if _, err := wc.Write(bts); err != nil {
9999
return err
@@ -144,9 +144,9 @@ func (g *GoogleCloudStorage) UploadDir(bucket, src, dst string, opts ...OpOption
144144
if ret.ContentType != "" {
145145
wc.ContentType = ret.ContentType
146146
}
147-
bts, err := ioutil.ReadFile(fpath)
147+
bts, err := os.ReadFile(fpath)
148148
if err != nil {
149-
errc <- fmt.Errorf("ioutil.ReadFile(%s) %v", fpath, err)
149+
errc <- fmt.Errorf("os.ReadFile(%s) %v", fpath, err)
150150
return
151151
}
152152
if _, err := wc.Write(bts); err != nil {

util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package dbtester
1717
import (
1818
"fmt"
1919
"io"
20-
"io/ioutil"
2120
mrand "math/rand"
2221
"net/http"
2322
"os"
@@ -90,7 +89,7 @@ func exist(fpath string) bool {
9089
// and closes it. This prevents TCP/TLS connections from closing,
9190
// therefore available for reuse.
9291
func gracefulClose(resp *http.Response) {
93-
io.Copy(ioutil.Discard, resp.Body)
92+
io.Copy(io.Discard, resp.Body)
9493
resp.Body.Close()
9594
}
9695

0 commit comments

Comments
 (0)