From c48fadc4a7655008d13076c7f757c36368e2ca13 Mon Sep 17 00:00:00 2001 From: KallyDev <36319157+kallydev@users.noreply.github.com> Date: Thu, 30 Sep 2021 01:17:48 +0800 Subject: Move from deprecated ioutil to os and io packages (#4364) --- caddyconfig/caddyfile/parse.go | 4 ++-- caddyconfig/caddyfile/parse_test.go | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'caddyconfig/caddyfile') diff --git a/caddyconfig/caddyfile/parse.go b/caddyconfig/caddyfile/parse.go index 0fe07ab..8591759 100755 --- a/caddyconfig/caddyfile/parse.go +++ b/caddyconfig/caddyfile/parse.go @@ -17,7 +17,7 @@ package caddyfile import ( "bytes" "fmt" - "io/ioutil" + "io" "log" "os" "path/filepath" @@ -447,7 +447,7 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) { return nil, p.Errf("Could not import %s: is a directory", importFile) } - input, err := ioutil.ReadAll(file) + input, err := io.ReadAll(file) if err != nil { return nil, p.Errf("Could not read imported file %s: %v", importFile, err) } diff --git a/caddyconfig/caddyfile/parse_test.go b/caddyconfig/caddyfile/parse_test.go index 0996ed0..8d43e1a 100755 --- a/caddyconfig/caddyfile/parse_test.go +++ b/caddyconfig/caddyfile/parse_test.go @@ -16,7 +16,6 @@ package caddyfile import ( "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -280,7 +279,7 @@ func TestRecursiveImport(t *testing.T) { } // test relative recursive import - err = ioutil.WriteFile(recursiveFile1, []byte( + err = os.WriteFile(recursiveFile1, []byte( `localhost dir1 import recursive_import_test2`), 0644) @@ -289,7 +288,7 @@ func TestRecursiveImport(t *testing.T) { } defer os.Remove(recursiveFile1) - err = ioutil.WriteFile(recursiveFile2, []byte("dir2 1"), 0644) + err = os.WriteFile(recursiveFile2, []byte("dir2 1"), 0644) if err != nil { t.Fatal(err) } @@ -314,7 +313,7 @@ func TestRecursiveImport(t *testing.T) { } // test absolute recursive import - err = ioutil.WriteFile(recursiveFile1, []byte( + err = os.WriteFile(recursiveFile1, []byte( `localhost dir1 import `+recursiveFile2), 0644) @@ -370,7 +369,7 @@ func TestDirectiveImport(t *testing.T) { t.Fatal(err) } - err = ioutil.WriteFile(directiveFile, []byte(`prop1 1 + err = os.WriteFile(directiveFile, []byte(`prop1 1 prop2 2`), 0644) if err != nil { t.Fatal(err) @@ -633,7 +632,7 @@ func TestSnippets(t *testing.T) { } func writeStringToTempFileOrDie(t *testing.T, str string) (pathToFile string) { - file, err := ioutil.TempFile("", t.Name()) + file, err := os.CreateTemp("", t.Name()) if err != nil { panic(err) // get a stack trace so we know where this was called from. } -- cgit v1.2.3