summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorKallyDev <36319157+kallydev@users.noreply.github.com>2021-09-30 01:17:48 +0800
committerGitHub <noreply@github.com>2021-09-29 11:17:48 -0600
commitc48fadc4a7655008d13076c7f757c36368e2ca13 (patch)
tree3fe2837e02e9b664dd5b86afbe42494ac20997f8 /caddyconfig
parent059fc32f002d00e980b438b3edbdf7b8bcdf9a90 (diff)
Move from deprecated ioutil to os and io packages (#4364)
Diffstat (limited to 'caddyconfig')
-rwxr-xr-xcaddyconfig/caddyfile/parse.go4
-rwxr-xr-xcaddyconfig/caddyfile/parse_test.go11
-rw-r--r--caddyconfig/httpcaddyfile/builtins.go4
-rw-r--r--caddyconfig/httploader.go7
4 files changed, 13 insertions, 13 deletions
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.
}
diff --git a/caddyconfig/httpcaddyfile/builtins.go b/caddyconfig/httpcaddyfile/builtins.go
index d52c5ef..7fdd3e8 100644
--- a/caddyconfig/httpcaddyfile/builtins.go
+++ b/caddyconfig/httpcaddyfile/builtins.go
@@ -19,8 +19,8 @@ import (
"encoding/pem"
"fmt"
"html"
- "io/ioutil"
"net/http"
+ "os"
"reflect"
"strconv"
"strings"
@@ -230,7 +230,7 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
return nil, h.ArgErr()
}
filename := h.Val()
- certDataPEM, err := ioutil.ReadFile(filename)
+ certDataPEM, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
diff --git a/caddyconfig/httploader.go b/caddyconfig/httploader.go
index d9e222b..396e153 100644
--- a/caddyconfig/httploader.go
+++ b/caddyconfig/httploader.go
@@ -18,8 +18,9 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
+ "os"
"time"
"github.com/caddyserver/caddy/v2"
@@ -95,7 +96,7 @@ func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) {
return nil, fmt.Errorf("server responded with HTTP %d", resp.StatusCode)
}
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
@@ -144,7 +145,7 @@ func (hl HTTPLoader) makeClient(ctx caddy.Context) (*http.Client, error) {
if len(hl.TLS.RootCAPEMFiles) > 0 {
rootPool := x509.NewCertPool()
for _, pemFile := range hl.TLS.RootCAPEMFiles {
- pemData, err := ioutil.ReadFile(pemFile)
+ pemData, err := os.ReadFile(pemFile)
if err != nil {
return nil, fmt.Errorf("failed reading ca cert: %v", err)
}