From be57f596c011ae04f250d266c3567bfab6e01630 Mon Sep 17 00:00:00 2001 From: yulog <29723448+yulog@users.noreply.github.com> Date: Sat, 6 Jul 2024 13:23:47 +0900 Subject: [PATCH] replace ioutil --- gocredits.go | 9 ++++----- gocredits_test.go | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/gocredits.go b/gocredits.go index 9078100..52c1653 100644 --- a/gocredits.go +++ b/gocredits.go @@ -6,7 +6,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "net/http" "os" @@ -124,7 +123,7 @@ func takeCredits(dir string, skipMissing bool) ([]*license, error) { lpath string ) for _, lpath = range []string{"LICENSE", "../LICENSE"} { - bs, err = ioutil.ReadFile(filepath.Join(goroot, lpath)) + bs, err = os.ReadFile(filepath.Join(goroot, lpath)) if err == nil { break } @@ -138,7 +137,7 @@ func takeCredits(dir string, skipMissing bool) ([]*license, error) { if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to fetch LICENSE of Go") } - bs, err = ioutil.ReadAll(resp.Body) + bs, err = io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -224,7 +223,7 @@ func takeCredits(dir string, skipMissing bool) ([]*license, error) { } func findLicense(dir string) (string, string, error) { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return "", "", err } @@ -246,7 +245,7 @@ func findLicense(dir string) (string, string, error) { if fileName == "" { return "", "", os.ErrNotExist } - bs, err := ioutil.ReadFile(filepath.Join(dir, fileName)) + bs, err := os.ReadFile(filepath.Join(dir, fileName)) if err != nil { return "", "", err } diff --git a/gocredits_test.go b/gocredits_test.go index a0d0ade..4aaba85 100644 --- a/gocredits_test.go +++ b/gocredits_test.go @@ -2,7 +2,6 @@ package gocredits import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -31,7 +30,7 @@ func TestLicenseDirs_set(t *testing.T) { } func TestTakeCredits(t *testing.T) { - tmpd, err := ioutil.TempDir("", "gocredits-") + tmpd, err := os.MkdirTemp("", "gocredits-") if err != nil { t.Fatal(err) }