fix: use of ioutil package (#5261)

* fix ioutil.NopCloser

* fix ioutil.ReadAll

* fix ioutil.ReadFile

* fix ioutil.WriteFile

* run goimports -w -format-only ./

* update CHANGELOG.md
This commit is contained in:
Kota
2023-06-25 19:48:23 +09:00
committed by GitHub
parent a04bf251c7
commit 6f803ec9a9
26 changed files with 73 additions and 85 deletions

View File

@@ -19,7 +19,6 @@ import (
"compress/gzip"
"errors"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
@@ -377,14 +376,14 @@ func (input *BeegoInput) CopyBody(MaxMemory int64) []byte {
if err != nil {
return nil
}
requestbody, _ = ioutil.ReadAll(reader)
requestbody, _ = io.ReadAll(reader)
} else {
requestbody, _ = ioutil.ReadAll(safe)
requestbody, _ = io.ReadAll(safe)
}
input.Context.Request.Body.Close()
bf := bytes.NewBuffer(requestbody)
input.Context.Request.Body = http.MaxBytesReader(input.Context.ResponseWriter, ioutil.NopCloser(bf), MaxMemory)
input.Context.Request.Body = http.MaxBytesReader(input.Context.ResponseWriter, io.NopCloser(bf), MaxMemory)
input.RequestBody = requestbody
return requestbody
}

View File

@@ -17,7 +17,6 @@ package web
import (
"bytes"
"io"
"io/ioutil"
"math"
"mime/multipart"
"net/http"
@@ -321,7 +320,7 @@ func testControllerRespTestCases(t *testing.T, tc respTestCase) {
t.Errorf("TestResponse() failed to validate response code for %s", tc.Accept)
}
bodyBytes, err := ioutil.ReadAll(response.Body)
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
t.Errorf("TestResponse() failed to parse response body for %s", tc.Accept)
}

View File

@@ -5,7 +5,6 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
@@ -194,7 +193,7 @@ func (srv *Server) ListenMutualTLS(certFile string, keyFile string, trustFile st
srv.TLSConfig.Certificates[0] = cert
srv.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert
pool := x509.NewCertPool()
data, err := ioutil.ReadFile(trustFile)
data, err := os.ReadFile(trustFile)
if err != nil {
log.Println(err)
return nil, err

View File

@@ -18,7 +18,6 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/fcgi"
@@ -257,7 +256,7 @@ func (app *HttpServer) Run(addr string, mws ...MiddleWare) {
app.Cfg.Listen.HTTPSCertFile, app.Cfg.Listen.HTTPSKeyFile = "", ""
} else if app.Cfg.Listen.EnableMutualHTTPS {
pool := x509.NewCertPool()
data, err := ioutil.ReadFile(app.Cfg.Listen.TrustCaFile)
data, err := os.ReadFile(app.Cfg.Listen.TrustCaFile)
if err != nil {
logs.Info("MutualHTTPS should provide TrustCaFile")
return

View File

@@ -18,7 +18,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path"
@@ -167,7 +167,7 @@ func (fp *FileProvider) SessionRead(ctx context.Context, sid string) (Store, err
os.Chtimes(sidPath, time.Now(), time.Now())
var kv map[interface{}]interface{}
b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return nil, err
}
@@ -257,7 +257,7 @@ func (fp *FileProvider) SessionRegenerate(ctx context.Context, oldsid, sid strin
// 4.return FileSessionStore
_, err = os.Stat(oldSidFile)
if err == nil {
b, err := ioutil.ReadFile(oldSidFile)
b, err := os.ReadFile(oldSidFile)
if err != nil {
return nil, err
}
@@ -272,7 +272,7 @@ func (fp *FileProvider) SessionRegenerate(ctx context.Context, oldsid, sid strin
}
}
ioutil.WriteFile(newSidFile, b, 0o777)
os.WriteFile(newSidFile, b, 0o777)
os.Remove(oldSidFile)
os.Chtimes(newSidFile, time.Now(), time.Now())
ss := &FileSessionStore{sid: sid, values: kv}

View File

@@ -6,7 +6,6 @@ import (
"compress/zlib"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -32,7 +31,7 @@ func testOpenFile(encoding string, content []byte, t *testing.T) {
func TestOpenStaticFile_1(t *testing.T) {
file, _ := os.Open(licenseFile)
content, _ := ioutil.ReadAll(file)
content, _ := io.ReadAll(file)
testOpenFile("", content, t)
}
@@ -42,7 +41,7 @@ func TestOpenStaticFileGzip_1(t *testing.T) {
fileWriter, _ := gzip.NewWriterLevel(&zipBuf, gzip.BestCompression)
io.Copy(fileWriter, file)
fileWriter.Close()
content, _ := ioutil.ReadAll(&zipBuf)
content, _ := io.ReadAll(&zipBuf)
testOpenFile("gzip", content, t)
}
@@ -53,7 +52,7 @@ func TestOpenStaticFileDeflate_1(t *testing.T) {
fileWriter, _ := zlib.NewWriterLevel(&zipBuf, zlib.BestCompression)
io.Copy(fileWriter, file)
fileWriter.Close()
content, _ := ioutil.ReadAll(&zipBuf)
content, _ := io.ReadAll(&zipBuf)
testOpenFile("deflate", content, t)
}
@@ -89,7 +88,7 @@ func assetOpenFileAndContent(sch *serveContentHolder, reader *serveContentReader
t.Log("static content file size not same")
t.Fail()
}
bs, _ := ioutil.ReadAll(reader)
bs, _ := io.ReadAll(reader)
for i, v := range content {
if v != bs[i] {
t.Log("content not same")

View File

@@ -19,7 +19,6 @@ import (
"fmt"
"html/template"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
@@ -250,7 +249,7 @@ func getTplDeep(root string, fs http.FileSystem, file string, parent string, t *
panic("can't find template file:" + file)
}
defer f.Close()
data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return nil, [][]string{}, err
}
@@ -324,7 +323,7 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod
logs.Trace("template file parse error, not success open file:", err)
continue
}
data, err = ioutil.ReadAll(f)
data, err = io.ReadAll(f)
f.Close()
if err != nil {
logs.Trace("template file parse error, not success read file:", err)