From 5df209b6d5ae2f9b6538897b1afcfc8b472f4995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 4 Aug 2022 11:34:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/caches/partial_ranges.go | 8 ++++---- internal/caches/storage_file_test.go | 4 ++-- internal/caches/writer_partial_file_test.go | 3 +-- internal/configs/api_config.go | 6 +++--- internal/iplibrary/ip2Region.go | 4 ++-- internal/iplibrary/manager_city.go | 5 ++--- internal/iplibrary/manager_country.go | 5 ++--- internal/iplibrary/manager_provider.go | 5 ++--- internal/iplibrary/manager_province.go | 5 ++--- internal/nodes/http_cache_task_manager.go | 3 +-- internal/nodes/http_request.go | 5 ++--- internal/nodes/http_request_auth.go | 4 ++-- internal/nodes/http_request_waf.go | 5 ++--- internal/nodes/http_writer.go | 3 +-- internal/nodes/node.go | 5 ++--- internal/nodes/node_panic.go | 3 +-- internal/nodes/system_services.go | 3 +-- internal/utils/http.go | 4 ++-- internal/utils/readers/reader_closer_byte_ranges_test.go | 5 ++--- internal/utils/service_linux.go | 7 +++---- internal/waf/action_block.go | 3 +-- internal/waf/checkpoints/request_all_test.go | 6 +++--- internal/waf/checkpoints/request_body_test.go | 6 +++--- internal/waf/checkpoints/request_form_arg_test.go | 4 ++-- internal/waf/checkpoints/request_json_arg_test.go | 8 ++++---- internal/waf/checkpoints/request_upload.go | 4 ++-- internal/waf/checkpoints/request_upload_test.go | 4 ++-- internal/waf/checkpoints/response_body.go | 6 +++--- internal/waf/checkpoints/response_body_test.go | 6 +++--- internal/waf/requests/test_request.go | 5 ++--- internal/waf/waf.go | 4 ++-- 31 files changed, 66 insertions(+), 82 deletions(-) diff --git a/internal/caches/partial_ranges.go b/internal/caches/partial_ranges.go index 0eb2cdd..52b5a1c 100644 --- a/internal/caches/partial_ranges.go +++ b/internal/caches/partial_ranges.go @@ -5,7 +5,7 @@ package caches import ( "encoding/json" "errors" - "io/ioutil" + "os" ) // PartialRanges 内容分区范围定义 @@ -30,7 +30,7 @@ func NewPartialRangesFromJSON(data []byte) (*PartialRanges, error) { } func NewPartialRangesFromFile(path string) (*PartialRanges, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, err } @@ -116,12 +116,12 @@ func (this *PartialRanges) WriteToFile(path string) error { if err != nil { return errors.New("convert to json failed: " + err.Error()) } - return ioutil.WriteFile(path, data, 0666) + return os.WriteFile(path, data, 0666) } // ReadFromFile 从文件中读取 func (this *PartialRanges) ReadFromFile(path string) (*PartialRanges, error) { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/internal/caches/storage_file_test.go b/internal/caches/storage_file_test.go index e8ab92b..77ee176 100644 --- a/internal/caches/storage_file_test.go +++ b/internal/caches/storage_file_test.go @@ -8,7 +8,7 @@ import ( "github.com/iwind/TeaGo/Tea" _ "github.com/iwind/TeaGo/bootstrap" "github.com/iwind/TeaGo/logs" - "io/ioutil" + "io" "net/http" "runtime" "strconv" @@ -152,7 +152,7 @@ func TestFileStorage_OpenWriter_HTTP(t *testing.T) { "Last-Modified": []string{"Wed, 06 Jan 2021 10:03:29 GMT"}, "Server": []string{"CDN-Server"}, }, - Body: ioutil.NopCloser(bytes.NewBuffer([]byte("THIS IS HTTP BODY"))), + Body: io.NopCloser(bytes.NewBuffer([]byte("THIS IS HTTP BODY"))), } for k, v := range resp.Header { diff --git a/internal/caches/writer_partial_file_test.go b/internal/caches/writer_partial_file_test.go index af50569..e1cfb48 100644 --- a/internal/caches/writer_partial_file_test.go +++ b/internal/caches/writer_partial_file_test.go @@ -5,7 +5,6 @@ package caches_test import ( "github.com/TeaOSLab/EdgeNode/internal/caches" "github.com/iwind/TeaGo/types" - "io/ioutil" "os" "testing" "time" @@ -16,7 +15,7 @@ func TestPartialFileWriter_Write(t *testing.T) { _ = os.Remove(path) var reader = func() { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { t.Fatal(err) } diff --git a/internal/configs/api_config.go b/internal/configs/api_config.go index 83cf967..d5be986 100644 --- a/internal/configs/api_config.go +++ b/internal/configs/api_config.go @@ -3,7 +3,7 @@ package configs import ( "github.com/iwind/TeaGo/Tea" "gopkg.in/yaml.v3" - "io/ioutil" + "os" ) // APIConfig 节点API配置 @@ -17,7 +17,7 @@ type APIConfig struct { } func LoadAPIConfig() (*APIConfig, error) { - data, err := ioutil.ReadFile(Tea.ConfigFile("api.yaml")) + data, err := os.ReadFile(Tea.ConfigFile("api.yaml")) if err != nil { return nil, err } @@ -37,6 +37,6 @@ func (this *APIConfig) WriteFile(path string) error { if err != nil { return err } - err = ioutil.WriteFile(path, data, 0666) + err = os.WriteFile(path, data, 0666) return err } diff --git a/internal/iplibrary/ip2Region.go b/internal/iplibrary/ip2Region.go index cbb77aa..484ee7d 100644 --- a/internal/iplibrary/ip2Region.go +++ b/internal/iplibrary/ip2Region.go @@ -4,7 +4,7 @@ package iplibrary import ( "errors" - "io/ioutil" + "os" "strconv" "strings" ) @@ -62,7 +62,7 @@ func getIpInfo(cityId int64, line []byte) *IpInfo { func NewIP2Region(path string) (*IP2Region, error) { var region = &IP2Region{} - region.dbData, err = ioutil.ReadFile(path) + region.dbData, err = os.ReadFile(path) if err != nil { return nil, err diff --git a/internal/iplibrary/manager_city.go b/internal/iplibrary/manager_city.go index 79a2b82..eb3b964 100644 --- a/internal/iplibrary/manager_city.go +++ b/internal/iplibrary/manager_city.go @@ -12,7 +12,6 @@ import ( "github.com/iwind/TeaGo/Tea" _ "github.com/iwind/TeaGo/bootstrap" "github.com/iwind/TeaGo/types" - "io/ioutil" "os" "sync" "time" @@ -90,7 +89,7 @@ func (this *CityManager) Lookup(provinceId int64, cityName string) (cityId int64 // 从缓存中读取 func (this *CityManager) load() error { - data, err := ioutil.ReadFile(this.cacheFile) + data, err := os.ReadFile(this.cacheFile) if err != nil { if os.IsNotExist(err) { return nil @@ -151,6 +150,6 @@ func (this *CityManager) loop() error { // 保存到本地缓存 - err = ioutil.WriteFile(this.cacheFile, data, 0666) + err = os.WriteFile(this.cacheFile, data, 0666) return err } diff --git a/internal/iplibrary/manager_country.go b/internal/iplibrary/manager_country.go index 93c12b8..3576dea 100644 --- a/internal/iplibrary/manager_country.go +++ b/internal/iplibrary/manager_country.go @@ -11,7 +11,6 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/rpc" "github.com/iwind/TeaGo/Tea" _ "github.com/iwind/TeaGo/bootstrap" - "io/ioutil" "os" "sync" "time" @@ -89,7 +88,7 @@ func (this *CountryManager) Lookup(countryName string) (countryId int64) { // 从缓存中读取 func (this *CountryManager) load() error { - data, err := ioutil.ReadFile(this.cacheFile) + data, err := os.ReadFile(this.cacheFile) if err != nil { if os.IsNotExist(err) { return nil @@ -149,6 +148,6 @@ func (this *CountryManager) loop() error { this.locker.Unlock() // 保存到本地缓存 - err = ioutil.WriteFile(this.cacheFile, data, 0666) + err = os.WriteFile(this.cacheFile, data, 0666) return err } diff --git a/internal/iplibrary/manager_provider.go b/internal/iplibrary/manager_provider.go index a08f5dc..128faa1 100644 --- a/internal/iplibrary/manager_provider.go +++ b/internal/iplibrary/manager_provider.go @@ -11,7 +11,6 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/rpc" "github.com/iwind/TeaGo/Tea" _ "github.com/iwind/TeaGo/bootstrap" - "io/ioutil" "os" "sync" "time" @@ -89,7 +88,7 @@ func (this *ProviderManager) Lookup(providerName string) (providerId int64) { // 从缓存中读取 func (this *ProviderManager) load() error { - data, err := ioutil.ReadFile(this.cacheFile) + data, err := os.ReadFile(this.cacheFile) if err != nil { if os.IsNotExist(err) { return nil @@ -150,6 +149,6 @@ func (this *ProviderManager) loop() error { // 保存到本地缓存 - err = ioutil.WriteFile(this.cacheFile, data, 0666) + err = os.WriteFile(this.cacheFile, data, 0666) return err } diff --git a/internal/iplibrary/manager_province.go b/internal/iplibrary/manager_province.go index fb5fe28..e668bd4 100644 --- a/internal/iplibrary/manager_province.go +++ b/internal/iplibrary/manager_province.go @@ -11,7 +11,6 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/rpc" "github.com/iwind/TeaGo/Tea" _ "github.com/iwind/TeaGo/bootstrap" - "io/ioutil" "os" "sync" "time" @@ -93,7 +92,7 @@ func (this *ProvinceManager) Lookup(provinceName string) (provinceId int64) { // 从缓存中读取 func (this *ProvinceManager) load() error { - data, err := ioutil.ReadFile(this.cacheFile) + data, err := os.ReadFile(this.cacheFile) if err != nil { if os.IsNotExist(err) { return nil @@ -156,6 +155,6 @@ func (this *ProvinceManager) loop() error { // 保存到本地缓存 - err = ioutil.WriteFile(this.cacheFile, data, 0666) + err = os.WriteFile(this.cacheFile, data, 0666) return err } diff --git a/internal/nodes/http_cache_task_manager.go b/internal/nodes/http_cache_task_manager.go index 3b0d837..8ee40f8 100644 --- a/internal/nodes/http_cache_task_manager.go +++ b/internal/nodes/http_cache_task_manager.go @@ -15,7 +15,6 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/rpc" "github.com/iwind/TeaGo/Tea" "io" - "io/ioutil" "net" "net/http" "regexp" @@ -236,7 +235,7 @@ func (this *HTTPCacheTaskManager) fetchKey(key *pb.HTTPCacheTaskKey) error { }() // 读取内容,以便于生成缓存 - _, _ = io.Copy(ioutil.Discard, resp.Body) + _, _ = io.Copy(io.Discard, resp.Body) // 处理502 if resp.StatusCode == http.StatusBadGateway { diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index bb9c341..2a67c68 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -17,7 +17,6 @@ import ( "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -284,12 +283,12 @@ func (this *HTTPRequest) doBegin() { this.web.AccessLogRef.IsOn && this.web.AccessLogRef.ContainsField(serverconfigs.HTTPAccessLogFieldRequestBody) { var err error - this.requestBodyData, err = ioutil.ReadAll(io.LimitReader(this.RawReq.Body, AccessLogMaxRequestBodySize)) + this.requestBodyData, err = io.ReadAll(io.LimitReader(this.RawReq.Body, AccessLogMaxRequestBodySize)) if err != nil { this.write50x(err, http.StatusBadGateway, "Failed to read request body for access log", "为访问日志读取请求Body失败", false) return } - this.RawReq.Body = ioutil.NopCloser(io.MultiReader(bytes.NewBuffer(this.requestBodyData), this.RawReq.Body)) + this.RawReq.Body = io.NopCloser(io.MultiReader(bytes.NewBuffer(this.requestBodyData), this.RawReq.Body)) } // 跳转 diff --git a/internal/nodes/http_request_auth.go b/internal/nodes/http_request_auth.go index d4a31f5..4fc9609 100644 --- a/internal/nodes/http_request_auth.go +++ b/internal/nodes/http_request_auth.go @@ -5,7 +5,7 @@ package nodes import ( "bytes" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" - "io/ioutil" + "io" "net/http" ) @@ -26,7 +26,7 @@ func (this *HTTPRequest) doAuth() (shouldStop bool) { subReq.Proto = this.RawReq.Proto subReq.ProtoMinor = this.RawReq.ProtoMinor subReq.ProtoMajor = this.RawReq.ProtoMajor - subReq.Body = ioutil.NopCloser(bytes.NewReader([]byte{})) + subReq.Body = io.NopCloser(bytes.NewReader([]byte{})) subReq.Header.Set("Referer", this.URL()) var writer = NewEmptyResponseWriter(this.writer) this.doSubRequest(writer, subReq) diff --git a/internal/nodes/http_request_waf.go b/internal/nodes/http_request_waf.go index db04083..8e429ef 100644 --- a/internal/nodes/http_request_waf.go +++ b/internal/nodes/http_request_waf.go @@ -11,7 +11,6 @@ import ( "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/types" "io" - "io/ioutil" "net/http" ) @@ -359,7 +358,7 @@ func (this *HTTPRequest) WAFSetCacheBody(body []byte) { // WAFReadBody 读取Body func (this *HTTPRequest) WAFReadBody(max int64) (data []byte, err error) { if this.RawReq.ContentLength > 0 { - data, err = ioutil.ReadAll(io.LimitReader(this.RawReq.Body, max)) + data, err = io.ReadAll(io.LimitReader(this.RawReq.Body, max)) } return @@ -368,7 +367,7 @@ func (this *HTTPRequest) WAFReadBody(max int64) (data []byte, err error) { // WAFRestoreBody 恢复Body func (this *HTTPRequest) WAFRestoreBody(data []byte) { if len(data) > 0 { - this.RawReq.Body = ioutil.NopCloser(io.MultiReader(bytes.NewBuffer(data), this.RawReq.Body)) + this.RawReq.Body = io.NopCloser(io.MultiReader(bytes.NewBuffer(data), this.RawReq.Body)) } } diff --git a/internal/nodes/http_writer.go b/internal/nodes/http_writer.go index c0dd1f5..ae9e047 100644 --- a/internal/nodes/http_writer.go +++ b/internal/nodes/http_writer.go @@ -26,7 +26,6 @@ import ( _ "image/jpeg" _ "image/png" "io" - "io/ioutil" "net" "net/http" "net/textproto" @@ -524,7 +523,7 @@ func (this *HTTPWriter) PrepareWebP(resp *http.Response, size int64) { this.webpOriginContentType = contentType this.webpIsEncoding = true - resp.Body = ioutil.NopCloser(&bytes.Buffer{}) + resp.Body = io.NopCloser(&bytes.Buffer{}) this.delayRead = true this.Header().Del("Content-Length") diff --git a/internal/nodes/node.go b/internal/nodes/node.go index fb63f4a..1d88937 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -30,7 +30,6 @@ import ( "github.com/iwind/TeaGo/types" "github.com/iwind/gosock/pkg/gosock" "gopkg.in/yaml.v3" - "io/ioutil" "log" "os" "os/exec" @@ -612,7 +611,7 @@ func (this *Node) startSyncTimer() { // 检查集群设置 func (this *Node) checkClusterConfig() error { configFile := Tea.ConfigFile("cluster.yaml") - data, err := ioutil.ReadFile(configFile) + data, err := os.ReadFile(configFile) if err != nil { return err } @@ -1008,7 +1007,7 @@ func (this *Node) checkDisk() { "/sys/block/vda/queue/rotational", "/sys/block/sda/queue/rotational", } { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { continue } diff --git a/internal/nodes/node_panic.go b/internal/nodes/node_panic.go index 8869d18..83a6201 100644 --- a/internal/nodes/node_panic.go +++ b/internal/nodes/node_panic.go @@ -9,7 +9,6 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/logs" - "io/ioutil" "os" "syscall" ) @@ -25,7 +24,7 @@ func (this *Node) handlePanic() { var panicFile = Tea.Root + "/logs/panic.log" // 分析panic - data, err := ioutil.ReadFile(panicFile) + data, err := os.ReadFile(panicFile) if err == nil { var index = bytes.Index(data, []byte("panic:")) if index >= 0 { diff --git a/internal/nodes/system_services.go b/internal/nodes/system_services.go index 8a9cafd..3a7cacf 100644 --- a/internal/nodes/system_services.go +++ b/internal/nodes/system_services.go @@ -11,7 +11,6 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/iwind/TeaGo/maps" - "io/ioutil" "os" "os/exec" "runtime" @@ -104,7 +103,7 @@ func (this *SystemServiceManager) setupSystemd(params maps.Map) error { if output == "enabled" { // 检查文件路径是否变化 - data, err := ioutil.ReadFile("/etc/systemd/system/" + teaconst.SystemdServiceName + ".service") + data, err := os.ReadFile("/etc/systemd/system/" + teaconst.SystemdServiceName + ".service") if err == nil && bytes.Index(data, []byte(exe)) > 0 { return nil } diff --git a/internal/utils/http.go b/internal/utils/http.go index c7253fd..877dd76 100644 --- a/internal/utils/http.go +++ b/internal/utils/http.go @@ -2,7 +2,7 @@ package utils import ( "crypto/tls" - "io/ioutil" + "io" "net/http" "net/http/httputil" "sync" @@ -19,7 +19,7 @@ func DumpResponse(resp *http.Response) (header []byte, body []byte, err error) { if err != nil { return } - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) return } diff --git a/internal/utils/readers/reader_closer_byte_ranges_test.go b/internal/utils/readers/reader_closer_byte_ranges_test.go index 894ac21..268d49c 100644 --- a/internal/utils/readers/reader_closer_byte_ranges_test.go +++ b/internal/utils/readers/reader_closer_byte_ranges_test.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/TeaOSLab/EdgeNode/internal/utils/readers" "io" - "io/ioutil" "net/textproto" "testing" ) @@ -17,7 +16,7 @@ func TestNewByteRangesReader(t *testing.T) { var dashBoundary = "--" + boundary var b = bytes.NewReader([]byte(dashBoundary + "\r\nContent-Range: bytes 0-4/36\r\nContent-Type: text/plain\r\n\r\n01234\r\n" + dashBoundary + "\r\nContent-Range: bytes 5-9/36\r\nContent-Type: text/plain\r\n\r\n56789\r\n--" + boundary + "\r\nContent-Range: bytes 10-12/36\r\nContent-Type: text/plain\r\n\r\nabc\r\n" + dashBoundary + "--\r\n")) - var reader = readers.NewByteRangesReaderCloser(ioutil.NopCloser(b), boundary) + var reader = readers.NewByteRangesReaderCloser(io.NopCloser(b), boundary) var p = make([]byte, 16) for { n, err := reader.Read(p) @@ -38,7 +37,7 @@ func TestByteRangesReader_OnPartRead(t *testing.T) { var dashBoundary = "--" + boundary var b = bytes.NewReader([]byte(dashBoundary + "\r\nContent-Range: bytes 0-4/36\r\nContent-Type: text/plain\r\n\r\n01234\r\n" + dashBoundary + "\r\nContent-Range: bytes 5-9/36\r\nContent-Type: text/plain\r\n\r\n56789\r\n--" + boundary + "\r\nContent-Range: bytes 10-12/36\r\nContent-Type: text/plain\r\n\r\nabc\r\n" + dashBoundary + "--\r\n")) - var reader = readers.NewByteRangesReaderCloser(ioutil.NopCloser(b), boundary) + var reader = readers.NewByteRangesReaderCloser(io.NopCloser(b), boundary) reader.OnPartRead(func(start int64, end int64, total int64, data []byte, header textproto.MIMEHeader) { t.Log(start, "-", end, "/", total, string(data)) }) diff --git a/internal/utils/service_linux.go b/internal/utils/service_linux.go index 9464465..28bd541 100644 --- a/internal/utils/service_linux.go +++ b/internal/utils/service_linux.go @@ -7,7 +7,6 @@ import ( teaconst "github.com/TeaOSLab/EdgeNode/internal/const" "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/files" - "io/ioutil" "os" "os/exec" "regexp" @@ -83,13 +82,13 @@ func (this *ServiceManager) installInitService(exePath string, args []string) er return errors.New("'scripts/" + shortName + "' file not exists") } - data, err := ioutil.ReadFile(scriptFile) + data, err := os.ReadFile(scriptFile) if err != nil { return err } data = regexp.MustCompile("INSTALL_DIR=.+").ReplaceAll(data, []byte("INSTALL_DIR="+Tea.Root)) - err = ioutil.WriteFile(initServiceFile, data, 0777) + err = os.WriteFile(initServiceFile, data, 0777) if err != nil { return err } @@ -137,7 +136,7 @@ ExecReload=` + exePath + ` reload WantedBy=multi-user.target` // write file - err := ioutil.WriteFile(systemdServiceFile, []byte(desc), 0777) + err := os.WriteFile(systemdServiceFile, []byte(desc), 0777) if err != nil { return err } diff --git a/internal/waf/action_block.go b/internal/waf/action_block.go index 39cc898..09ed741 100644 --- a/internal/waf/action_block.go +++ b/internal/waf/action_block.go @@ -7,7 +7,6 @@ import ( "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/logs" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -111,7 +110,7 @@ func (this *BlockAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, reque path = Tea.Root + string(os.PathSeparator) + path } - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { logs.Error(err) return false diff --git a/internal/waf/checkpoints/request_all_test.go b/internal/waf/checkpoints/request_all_test.go index 6eaa6f8..9ac8def 100644 --- a/internal/waf/checkpoints/request_all_test.go +++ b/internal/waf/checkpoints/request_all_test.go @@ -4,7 +4,7 @@ import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/iwind/TeaGo/types" - "io/ioutil" + "io" "net/http" "runtime" "strings" @@ -28,7 +28,7 @@ func TestRequestAllCheckpoint_RequestValue(t *testing.T) { t.Log(v) t.Log(types.String(v)) - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { t.Fatal(err) } @@ -48,7 +48,7 @@ func TestRequestAllCheckpoint_RequestValue_Max(t *testing.T) { } t.Log("value bytes:", len(types.String(value))) - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { t.Fatal(err) } diff --git a/internal/waf/checkpoints/request_body_test.go b/internal/waf/checkpoints/request_body_test.go index 124c57e..ef5267b 100644 --- a/internal/waf/checkpoints/request_body_test.go +++ b/internal/waf/checkpoints/request_body_test.go @@ -4,7 +4,7 @@ import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/iwind/TeaGo/types" - "io/ioutil" + "io" "net/http" "strings" "testing" @@ -19,7 +19,7 @@ func TestRequestBodyCheckpoint_RequestValue(t *testing.T) { checkpoint := new(RequestBodyCheckpoint) t.Log(checkpoint.RequestValue(req, "", nil, 1)) - body, err := ioutil.ReadAll(rawReq.Body) + body, err := io.ReadAll(rawReq.Body) if err != nil { t.Fatal(err) } @@ -40,7 +40,7 @@ func TestRequestBodyCheckpoint_RequestValue_Max(t *testing.T) { } t.Log("value bytes:", len(types.String(value))) - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { t.Fatal(err) } diff --git a/internal/waf/checkpoints/request_form_arg_test.go b/internal/waf/checkpoints/request_form_arg_test.go index a60aa66..25a16d8 100644 --- a/internal/waf/checkpoints/request_form_arg_test.go +++ b/internal/waf/checkpoints/request_form_arg_test.go @@ -3,7 +3,7 @@ package checkpoints import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" - "io/ioutil" + "io" "net/http" "net/url" "testing" @@ -24,7 +24,7 @@ func TestRequestFormArgCheckpoint_RequestValue(t *testing.T) { t.Log(checkpoint.RequestValue(req, "Hello", nil, 1)) t.Log(checkpoint.RequestValue(req, "encoded", nil, 1)) - body, err := ioutil.ReadAll(req.WAFRaw().Body) + body, err := io.ReadAll(req.WAFRaw().Body) if err != nil { t.Fatal(err) } diff --git a/internal/waf/checkpoints/request_json_arg_test.go b/internal/waf/checkpoints/request_json_arg_test.go index d968bc1..095a3f5 100644 --- a/internal/waf/checkpoints/request_json_arg_test.go +++ b/internal/waf/checkpoints/request_json_arg_test.go @@ -3,7 +3,7 @@ package checkpoints import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" - "io/ioutil" + "io" "net/http" "testing" ) @@ -31,7 +31,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Map(t *testing.T) { t.Log(checkpoint.RequestValue(req, "books", nil, 1)) t.Log(checkpoint.RequestValue(req, "books.1", nil, 1)) - body, err := ioutil.ReadAll(req.WAFRaw().Body) + body, err := io.ReadAll(req.WAFRaw().Body) if err != nil { t.Fatal(err) } @@ -61,7 +61,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Array(t *testing.T) { t.Log(checkpoint.RequestValue(req, "0.books", nil, 1)) t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1)) - body, err := ioutil.ReadAll(req.WAFRaw().Body) + body, err := io.ReadAll(req.WAFRaw().Body) if err != nil { t.Fatal(err) } @@ -91,7 +91,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Error(t *testing.T) { t.Log(checkpoint.RequestValue(req, "0.books", nil, 1)) t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1)) - body, err := ioutil.ReadAll(req.WAFRaw().Body) + body, err := io.ReadAll(req.WAFRaw().Body) if err != nil { t.Fatal(err) } diff --git a/internal/waf/checkpoints/request_upload.go b/internal/waf/checkpoints/request_upload.go index cf1498a..dce44d4 100644 --- a/internal/waf/checkpoints/request_upload.go +++ b/internal/waf/checkpoints/request_upload.go @@ -6,7 +6,7 @@ import ( "github.com/TeaOSLab/EdgeNode/internal/waf/utils" "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/maps" - "io/ioutil" + "io" "net/http" "path/filepath" "strings" @@ -51,7 +51,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st defer req.WAFRestoreBody(data) } oldBody := req.WAFRaw().Body - req.WAFRaw().Body = ioutil.NopCloser(bytes.NewBuffer(bodyData)) + req.WAFRaw().Body = io.NopCloser(bytes.NewBuffer(bodyData)) err := req.WAFRaw().ParseMultipartForm(utils.MaxBodySize) diff --git a/internal/waf/checkpoints/request_upload_test.go b/internal/waf/checkpoints/request_upload_test.go index eed421f..6ae0089 100644 --- a/internal/waf/checkpoints/request_upload_test.go +++ b/internal/waf/checkpoints/request_upload_test.go @@ -3,7 +3,7 @@ package checkpoints import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" - "io/ioutil" + "io" "mime/multipart" "net/http" "testing" @@ -94,7 +94,7 @@ func TestRequestUploadCheckpoint_RequestValue(t *testing.T) { t.Log(checkpoint.RequestValue(req, "name", nil, 1)) t.Log(checkpoint.RequestValue(req, "ext", nil, 1)) - data, err := ioutil.ReadAll(req.WAFRaw().Body) + data, err := io.ReadAll(req.WAFRaw().Body) if err != nil { t.Fatal(err) } diff --git a/internal/waf/checkpoints/response_body.go b/internal/waf/checkpoints/response_body.go index cc7f24a..0ee8548 100644 --- a/internal/waf/checkpoints/response_body.go +++ b/internal/waf/checkpoints/response_body.go @@ -4,7 +4,7 @@ import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/iwind/TeaGo/maps" - "io/ioutil" + "io" ) // ResponseBodyCheckpoint ${responseBody} @@ -33,7 +33,7 @@ func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *re value = string(resp.BodyData) return } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { sysErr = err return @@ -41,7 +41,7 @@ func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *re resp.BodyData = body _ = resp.Body.Close() value = body - resp.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + resp.Body = io.NopCloser(bytes.NewBuffer(body)) } return } diff --git a/internal/waf/checkpoints/response_body_test.go b/internal/waf/checkpoints/response_body_test.go index 85d68e0..f36114d 100644 --- a/internal/waf/checkpoints/response_body_test.go +++ b/internal/waf/checkpoints/response_body_test.go @@ -3,7 +3,7 @@ package checkpoints import ( "bytes" "github.com/TeaOSLab/EdgeNode/internal/waf/requests" - "io/ioutil" + "io" "net/http" "testing" ) @@ -13,7 +13,7 @@ func TestResponseBodyCheckpoint_ResponseValue(t *testing.T) { resp.StatusCode = 200 resp.Header = http.Header{} resp.Header.Set("Hello", "World") - resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte("Hello, World"))) + resp.Body = io.NopCloser(bytes.NewBuffer([]byte("Hello, World"))) checkpoint := new(ResponseBodyCheckpoint) t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1)) @@ -21,7 +21,7 @@ func TestResponseBodyCheckpoint_ResponseValue(t *testing.T) { t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1)) t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1)) - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { t.Fatal(err) } diff --git a/internal/waf/requests/test_request.go b/internal/waf/requests/test_request.go index 8b67b09..ab9b218 100644 --- a/internal/waf/requests/test_request.go +++ b/internal/waf/requests/test_request.go @@ -5,7 +5,6 @@ package requests import ( "bytes" "io" - "io/ioutil" "net" "net/http" ) @@ -48,7 +47,7 @@ func (this *TestRequest) WAFRemoteIP() string { func (this *TestRequest) WAFReadBody(max int64) (data []byte, err error) { if this.req.ContentLength > 0 { - data, err = ioutil.ReadAll(io.LimitReader(this.req.Body, max)) + data, err = io.ReadAll(io.LimitReader(this.req.Body, max)) } return } @@ -58,7 +57,7 @@ func (this *TestRequest) WAFRestoreBody(data []byte) { rawReader := bytes.NewBuffer(data) buf := make([]byte, 1024) _, _ = io.CopyBuffer(rawReader, this.req.Body, buf) - this.req.Body = ioutil.NopCloser(rawReader) + this.req.Body = io.NopCloser(rawReader) } } diff --git a/internal/waf/waf.go b/internal/waf/waf.go index 0936598..6d73995 100644 --- a/internal/waf/waf.go +++ b/internal/waf/waf.go @@ -10,8 +10,8 @@ import ( "github.com/iwind/TeaGo/files" "github.com/iwind/TeaGo/types" "gopkg.in/yaml.v3" - "io/ioutil" "net/http" + "os" "reflect" ) @@ -315,7 +315,7 @@ func (this *WAF) Save(path string) error { if err != nil { return err } - return ioutil.WriteFile(path, data, 0644) + return os.WriteFile(path, data, 0644) } func (this *WAF) ContainsGroupCode(code string) bool {