From 2e955d89d9ce0d1a08d5da0f670f9e8254b73fa4 Mon Sep 17 00:00:00 2001 From: Francesc Campoy Date: Wed, 11 Feb 2026 17:21:29 -0800 Subject: [PATCH] Replace deprecated io/ioutil with io and os equivalents io/ioutil has been deprecated since Go 1.16. This migrates all usages to their modern replacements: - ioutil.ReadAll -> io.ReadAll - ioutil.ReadFile -> os.ReadFile - ioutil.NopCloser -> io.NopCloser Co-Authored-By: Claude Opus 4.6 --- embedmd/content.go | 7 ++++--- integration_test.go | 4 ++-- main.go | 3 +-- main_test.go | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/embedmd/content.go b/embedmd/content.go index b9001af..be23501 100644 --- a/embedmd/content.go +++ b/embedmd/content.go @@ -15,8 +15,9 @@ package embedmd import ( "fmt" - "io/ioutil" + "io" "net/http" + "os" "path/filepath" "strings" ) @@ -36,7 +37,7 @@ type fetcher struct{} func (fetcher) Fetch(dir, path string) ([]byte, error) { if !strings.HasPrefix(path, "http://") && !strings.HasPrefix(path, "https://") { path = filepath.Join(dir, filepath.FromSlash(path)) - return ioutil.ReadFile(path) + return os.ReadFile(path) } res, err := http.Get(path) @@ -47,5 +48,5 @@ func (fetcher) Fetch(dir, path string) ([]byte, error) { if res.StatusCode != http.StatusOK { return nil, fmt.Errorf("status %s", res.Status) } - return ioutil.ReadAll(res.Body) + return io.ReadAll(res.Body) } diff --git a/integration_test.go b/integration_test.go index f6e4ace..352c328 100644 --- a/integration_test.go +++ b/integration_test.go @@ -1,7 +1,7 @@ package main import ( - "io/ioutil" + "os" "os/exec" "path/filepath" "testing" @@ -14,7 +14,7 @@ func TestIntegration(t *testing.T) { if err != nil { t.Fatalf("could not process file (%v): %s", err, got) } - wants, err := ioutil.ReadFile(filepath.Join("sample", "result.md")) + wants, err := os.ReadFile(filepath.Join("sample", "result.md")) if err != nil { t.Fatalf("could not read result: %v", err) } diff --git a/main.go b/main.go index bdbe8d4..018bcf4 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "os" "path/filepath" @@ -132,7 +131,7 @@ func readFile(path string) ([]byte, error) { return nil, err } defer f.Close() - return ioutil.ReadAll(f) + return io.ReadAll(f) } func processFile(path string, rewrite, doDiff bool) (foundDiff bool, err error) { diff --git a/main_test.go b/main_test.go index 17ba4f1..904bcf5 100644 --- a/main_test.go +++ b/main_test.go @@ -16,7 +16,6 @@ package main import ( "bytes" "io" - "io/ioutil" "os" "strings" "testing" @@ -146,7 +145,7 @@ func (f *fakeFile) WriteAt(b []byte, offset int64) (int, error) { return f.buf.W func (f *fakeFile) Truncate(int64) error { return nil } func newFakeFile(s string) *fakeFile { - return &fakeFile{ReadCloser: ioutil.NopCloser(strings.NewReader(s))} + return &fakeFile{ReadCloser: io.NopCloser(strings.NewReader(s))} } func newOpenFunc(files map[string]string) func(string) (file, error) {