summaryrefslogtreecommitdiff
path: root/modules
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 /modules
parent059fc32f002d00e980b438b3edbdf7b8bcdf9a90 (diff)
Move from deprecated ioutil to os and io packages (#4364)
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/replacer.go3
-rw-r--r--modules/caddyhttp/reverseproxy/fastcgi/client.go3
-rw-r--r--modules/caddyhttp/reverseproxy/fastcgi/client_test.go3
-rw-r--r--modules/caddyhttp/reverseproxy/healthchecks.go5
-rw-r--r--modules/caddyhttp/reverseproxy/httptransport.go4
-rw-r--r--modules/caddyhttp/staticresp_test.go4
-rw-r--r--modules/caddyhttp/templates/tplcontext_test.go9
-rw-r--r--modules/caddypki/crypto.go6
-rw-r--r--modules/caddytls/acmeissuer.go4
-rw-r--r--modules/caddytls/connpolicy.go4
-rw-r--r--modules/caddytls/fileloader.go6
-rw-r--r--modules/caddytls/folderloader.go3
12 files changed, 24 insertions, 30 deletions
diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go
index d0767f0..4d27a84 100644
--- a/modules/caddyhttp/replacer.go
+++ b/modules/caddyhttp/replacer.go
@@ -28,7 +28,6 @@ import (
"encoding/pem"
"fmt"
"io"
- "io/ioutil"
"net"
"net/http"
"net/textproto"
@@ -162,7 +161,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
return "", true
}
// replace real body with buffered data
- req.Body = ioutil.NopCloser(buf)
+ req.Body = io.NopCloser(buf)
return buf.String(), true
// original request, before any internal changes
diff --git a/modules/caddyhttp/reverseproxy/fastcgi/client.go b/modules/caddyhttp/reverseproxy/fastcgi/client.go
index 94df0c7..0772053 100644
--- a/modules/caddyhttp/reverseproxy/fastcgi/client.go
+++ b/modules/caddyhttp/reverseproxy/fastcgi/client.go
@@ -30,7 +30,6 @@ import (
"encoding/binary"
"errors"
"io"
- "io/ioutil"
"mime/multipart"
"net"
"net/http"
@@ -445,7 +444,7 @@ func (c *FCGIClient) Request(p map[string]string, req io.Reader) (resp *http.Res
if chunked(resp.TransferEncoding) {
resp.Body = clientCloser{c, httputil.NewChunkedReader(rb)}
} else {
- resp.Body = clientCloser{c, ioutil.NopCloser(rb)}
+ resp.Body = clientCloser{c, io.NopCloser(rb)}
}
return
}
diff --git a/modules/caddyhttp/reverseproxy/fastcgi/client_test.go b/modules/caddyhttp/reverseproxy/fastcgi/client_test.go
index f0740a4..ef3474d 100644
--- a/modules/caddyhttp/reverseproxy/fastcgi/client_test.go
+++ b/modules/caddyhttp/reverseproxy/fastcgi/client_test.go
@@ -26,7 +26,6 @@ import (
"encoding/binary"
"fmt"
"io"
- "io/ioutil"
"log"
"math/rand"
"net"
@@ -166,7 +165,7 @@ func sendFcgi(reqType int, fcgiParams map[string]string, data []byte, posts map[
}
defer resp.Body.Close()
- content, _ = ioutil.ReadAll(resp.Body)
+ content, _ = io.ReadAll(resp.Body)
log.Println("c: send data length ≈", length, string(content))
fcgi.Close()
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go
index 8d5bd77..230bf3a 100644
--- a/modules/caddyhttp/reverseproxy/healthchecks.go
+++ b/modules/caddyhttp/reverseproxy/healthchecks.go
@@ -18,7 +18,6 @@ import (
"context"
"fmt"
"io"
- "io/ioutil"
"log"
"net"
"net/http"
@@ -282,7 +281,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, host H
}
defer func() {
// drain any remaining body so connection could be re-used
- _, _ = io.Copy(ioutil.Discard, body)
+ _, _ = io.Copy(io.Discard, body)
resp.Body.Close()
}()
@@ -313,7 +312,7 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, host H
// if body does not match regex, mark down
if h.HealthChecks.Active.bodyRegexp != nil {
- bodyBytes, err := ioutil.ReadAll(body)
+ bodyBytes, err := io.ReadAll(body)
if err != nil {
h.HealthChecks.Active.logger.Info("failed to read response body",
zap.String("host", hostAddr),
diff --git a/modules/caddyhttp/reverseproxy/httptransport.go b/modules/caddyhttp/reverseproxy/httptransport.go
index 1932851..35bc947 100644
--- a/modules/caddyhttp/reverseproxy/httptransport.go
+++ b/modules/caddyhttp/reverseproxy/httptransport.go
@@ -20,10 +20,10 @@ import (
"crypto/x509"
"encoding/base64"
"fmt"
- "io/ioutil"
weakrand "math/rand"
"net"
"net/http"
+ "os"
"reflect"
"time"
@@ -364,7 +364,7 @@ func (t TLSConfig) MakeTLSClientConfig(ctx caddy.Context) (*tls.Config, error) {
rootPool.AddCert(caCert)
}
for _, pemFile := range t.RootCAPEMFiles {
- pemData, err := ioutil.ReadFile(pemFile)
+ pemData, err := os.ReadFile(pemFile)
if err != nil {
return nil, fmt.Errorf("failed reading ca cert: %v", err)
}
diff --git a/modules/caddyhttp/staticresp_test.go b/modules/caddyhttp/staticresp_test.go
index cd0d1a1..5844f43 100644
--- a/modules/caddyhttp/staticresp_test.go
+++ b/modules/caddyhttp/staticresp_test.go
@@ -16,7 +16,7 @@ package caddyhttp
import (
"context"
- "io/ioutil"
+ "io"
"net/http"
"net/http/httptest"
"strconv"
@@ -44,7 +44,7 @@ func TestStaticResponseHandler(t *testing.T) {
}
resp := w.Result()
- respBody, _ := ioutil.ReadAll(resp.Body)
+ respBody, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusNotFound {
t.Errorf("expected status %d but got %d", http.StatusNotFound, resp.StatusCode)
diff --git a/modules/caddyhttp/templates/tplcontext_test.go b/modules/caddyhttp/templates/tplcontext_test.go
index 1d15ca7..c2fe61f 100644
--- a/modules/caddyhttp/templates/tplcontext_test.go
+++ b/modules/caddyhttp/templates/tplcontext_test.go
@@ -17,7 +17,6 @@ package templates
import (
"bytes"
"fmt"
- "io/ioutil"
"net/http"
"os"
"path/filepath"
@@ -118,7 +117,7 @@ func TestImport(t *testing.T) {
// create files for test case
if test.fileName != "" {
absFilePath := filepath.Join(fmt.Sprintf("%s", context.Root), test.fileName)
- if err := ioutil.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
+ if err := os.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
os.Remove(absFilePath)
t.Fatalf("Test %d: Expected no error creating file, got: '%s'", i, err.Error())
}
@@ -198,7 +197,7 @@ func TestInclude(t *testing.T) {
// create files for test case
if test.fileName != "" {
absFilePath := filepath.Join(fmt.Sprintf("%s", context.Root), test.fileName)
- if err := ioutil.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
+ if err := os.WriteFile(absFilePath, []byte(test.fileContent), os.ModePerm); err != nil {
os.Remove(absFilePath)
t.Fatalf("Test %d: Expected no error creating file, got: '%s'", i, err.Error())
}
@@ -357,13 +356,13 @@ func TestFileListing(t *testing.T) {
// create files for test case
if test.fileNames != nil {
- dirPath, err = ioutil.TempDir(fmt.Sprintf("%s", context.Root), "caddy_ctxtest")
+ dirPath, err = os.MkdirTemp(fmt.Sprintf("%s", context.Root), "caddy_ctxtest")
if err != nil {
t.Fatalf("Test %d: Expected no error creating directory, got: '%s'", i, err.Error())
}
for _, name := range test.fileNames {
absFilePath := filepath.Join(dirPath, name)
- if err = ioutil.WriteFile(absFilePath, []byte(""), os.ModePerm); err != nil {
+ if err = os.WriteFile(absFilePath, []byte(""), os.ModePerm); err != nil {
os.RemoveAll(dirPath)
t.Fatalf("Test %d: Expected no error creating file, got: '%s'", i, err.Error())
}
diff --git a/modules/caddypki/crypto.go b/modules/caddypki/crypto.go
index e1a0e35..d8e72c6 100644
--- a/modules/caddypki/crypto.go
+++ b/modules/caddypki/crypto.go
@@ -23,7 +23,7 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
- "io/ioutil"
+ "os"
"strings"
)
@@ -137,11 +137,11 @@ type KeyPair struct {
func (kp KeyPair) Load() (*x509.Certificate, interface{}, error) {
switch kp.Format {
case "", "pem_file":
- certData, err := ioutil.ReadFile(kp.Certificate)
+ certData, err := os.ReadFile(kp.Certificate)
if err != nil {
return nil, nil, err
}
- keyData, err := ioutil.ReadFile(kp.PrivateKey)
+ keyData, err := os.ReadFile(kp.PrivateKey)
if err != nil {
return nil, nil, err
}
diff --git a/modules/caddytls/acmeissuer.go b/modules/caddytls/acmeissuer.go
index 9a7e73c..42cef02 100644
--- a/modules/caddytls/acmeissuer.go
+++ b/modules/caddytls/acmeissuer.go
@@ -18,8 +18,8 @@ import (
"context"
"crypto/x509"
"fmt"
- "io/ioutil"
"net/url"
+ "os"
"strconv"
"time"
@@ -152,7 +152,7 @@ func (iss *ACMEIssuer) Provision(ctx caddy.Context) error {
if len(iss.TrustedRootsPEMFiles) > 0 {
iss.rootPool = x509.NewCertPool()
for _, pemFile := range iss.TrustedRootsPEMFiles {
- pemData, err := ioutil.ReadFile(pemFile)
+ pemData, err := os.ReadFile(pemFile)
if err != nil {
return fmt.Errorf("loading trusted root CA's PEM file: %s: %v", pemFile, err)
}
diff --git a/modules/caddytls/connpolicy.go b/modules/caddytls/connpolicy.go
index 6c7fe3f..65cda5f 100644
--- a/modules/caddytls/connpolicy.go
+++ b/modules/caddytls/connpolicy.go
@@ -19,7 +19,7 @@ import (
"crypto/x509"
"encoding/base64"
"fmt"
- "io/ioutil"
+ "os"
"strings"
"github.com/caddyserver/caddy/v2"
@@ -369,7 +369,7 @@ func (clientauth *ClientAuthentication) ConfigureTLSConfig(cfg *tls.Config) erro
caPool.AddCert(clientCA)
}
for _, pemFile := range clientauth.TrustedCACertPEMFiles {
- pemContents, err := ioutil.ReadFile(pemFile)
+ pemContents, err := os.ReadFile(pemFile)
if err != nil {
return fmt.Errorf("reading %s: %v", pemFile, err)
}
diff --git a/modules/caddytls/fileloader.go b/modules/caddytls/fileloader.go
index fdf5486..430932b 100644
--- a/modules/caddytls/fileloader.go
+++ b/modules/caddytls/fileloader.go
@@ -17,7 +17,7 @@ package caddytls
import (
"crypto/tls"
"fmt"
- "io/ioutil"
+ "os"
"github.com/caddyserver/caddy/v2"
)
@@ -59,11 +59,11 @@ type CertKeyFilePair struct {
func (fl FileLoader) LoadCertificates() ([]Certificate, error) {
certs := make([]Certificate, 0, len(fl))
for _, pair := range fl {
- certData, err := ioutil.ReadFile(pair.Certificate)
+ certData, err := os.ReadFile(pair.Certificate)
if err != nil {
return nil, err
}
- keyData, err := ioutil.ReadFile(pair.Key)
+ keyData, err := os.ReadFile(pair.Key)
if err != nil {
return nil, err
}
diff --git a/modules/caddytls/folderloader.go b/modules/caddytls/folderloader.go
index 10b017e..0ff0629 100644
--- a/modules/caddytls/folderloader.go
+++ b/modules/caddytls/folderloader.go
@@ -19,7 +19,6 @@ import (
"crypto/tls"
"encoding/pem"
"fmt"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -79,7 +78,7 @@ func (fl FolderLoader) LoadCertificates() ([]Certificate, error) {
}
func x509CertFromCertAndKeyPEMFile(fpath string) (tls.Certificate, error) {
- bundle, err := ioutil.ReadFile(fpath)
+ bundle, err := os.ReadFile(fpath)
if err != nil {
return tls.Certificate{}, err
}