diff --git a/internal/accesslogs/storage_es.go b/internal/accesslogs/storage_es.go index 1ef26179..8cd36e32 100644 --- a/internal/accesslogs/storage_es.go +++ b/internal/accesslogs/storage_es.go @@ -10,7 +10,7 @@ import ( "github.com/TeaOSLab/EdgeAPI/internal/utils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" - "io/ioutil" + "io" "net/http" "regexp" "strings" @@ -118,7 +118,7 @@ func (this *ESStorage) Write(accessLogs []*pb.HTTPAccessLog) error { }() if resp.StatusCode != http.StatusOK { - bodyData, _ := ioutil.ReadAll(resp.Body) + bodyData, _ := io.ReadAll(resp.Body) return errors.New("ElasticSearch response status code: " + fmt.Sprintf("%d", resp.StatusCode) + " content: " + string(bodyData)) } diff --git a/internal/acme/acme_test.go b/internal/acme/acme_test.go index a2a030ce..a403ab60 100644 --- a/internal/acme/acme_test.go +++ b/internal/acme/acme_test.go @@ -10,7 +10,7 @@ import ( "github.com/go-acme/lego/v4/challenge/dns01" "github.com/go-acme/lego/v4/lego" acmelog "github.com/go-acme/lego/v4/log" - "io/ioutil" + "io" "log" "testing" @@ -50,7 +50,7 @@ func (this *MyProvider) CleanUp(domain, token, keyAuth string) error { // 参考 https://go-acme.github.io/lego/usage/library/ func TestGenerate(t *testing.T) { - acmelog.Logger = log.New(ioutil.Discard, "", log.LstdFlags) + acmelog.Logger = log.New(io.Discard, "", log.LstdFlags) // 生成私钥 privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) @@ -94,7 +94,7 @@ func TestGenerate(t *testing.T) { } func TestGenerate_EAB(t *testing.T) { - acmelog.Logger = log.New(ioutil.Discard, "", log.LstdFlags) + acmelog.Logger = log.New(io.Discard, "", log.LstdFlags) // 生成私钥 privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) diff --git a/internal/acme/request.go b/internal/acme/request.go index 557aaccf..2c28be6e 100644 --- a/internal/acme/request.go +++ b/internal/acme/request.go @@ -8,7 +8,7 @@ import ( "github.com/go-acme/lego/v4/lego" acmelog "github.com/go-acme/lego/v4/log" "github.com/go-acme/lego/v4/registration" - "io/ioutil" + "io" "log" ) @@ -55,7 +55,7 @@ func (this *Request) Run() (certData []byte, keyData []byte, err error) { func (this *Request) runDNS() (certData []byte, keyData []byte, err error) { if !this.debug { - acmelog.Logger = log.New(ioutil.Discard, "", log.LstdFlags) + acmelog.Logger = log.New(io.Discard, "", log.LstdFlags) } if this.task.User == nil { @@ -138,7 +138,7 @@ func (this *Request) runDNS() (certData []byte, keyData []byte, err error) { func (this *Request) runHTTP() (certData []byte, keyData []byte, err error) { if !this.debug { - acmelog.Logger = log.New(ioutil.Discard, "", log.LstdFlags) + acmelog.Logger = log.New(io.Discard, "", log.LstdFlags) } if this.task.User == nil { diff --git a/internal/configs/api_config.go b/internal/configs/api_config.go index 0a8a8d21..34805b17 100644 --- a/internal/configs/api_config.go +++ b/internal/configs/api_config.go @@ -4,7 +4,6 @@ import ( teaconst "github.com/TeaOSLab/EdgeAPI/internal/const" "github.com/iwind/TeaGo/Tea" "gopkg.in/yaml.v3" - "io/ioutil" "os" "path/filepath" ) @@ -42,7 +41,7 @@ func SharedAPIConfig() (*APIConfig, error) { var data []byte var err error for _, path := range paths { - data, err = ioutil.ReadFile(path) + data, err = os.ReadFile(path) if err == nil { if path == localFile { isFromLocal = true @@ -63,7 +62,7 @@ func SharedAPIConfig() (*APIConfig, error) { if !isFromLocal { // 恢复文件 - _ = ioutil.WriteFile(localFile, data, 0666) + _ = os.WriteFile(localFile, data, 0666) } // 恢复数据库文件 @@ -80,9 +79,9 @@ func SharedAPIConfig() (*APIConfig, error) { for _, path := range paths { _, err := os.Stat(path) if err == nil { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err == nil { - _ = ioutil.WriteFile(dbConfigFile, data, 0666) + _ = os.WriteFile(dbConfigFile, data, 0666) break } } @@ -122,14 +121,14 @@ func (this *APIConfig) WriteFile(path string) error { for _, backupDir := range backupDirs { stat, err := os.Stat(backupDir) if err == nil && stat.IsDir() { - _ = ioutil.WriteFile(backupDir+"/"+filename, data, 0666) + _ = os.WriteFile(backupDir+"/"+filename, data, 0666) } else if err != nil && os.IsNotExist(err) { err = os.Mkdir(backupDir, 0777) if err == nil { - _ = ioutil.WriteFile(backupDir+"/"+filename, data, 0666) + _ = os.WriteFile(backupDir+"/"+filename, data, 0666) } } } - return ioutil.WriteFile(path, data, 0666) + return os.WriteFile(path, data, 0666) } diff --git a/internal/dnsclients/provider_cloud_flare.go b/internal/dnsclients/provider_cloud_flare.go index 51a1f675..00c30fba 100644 --- a/internal/dnsclients/provider_cloud_flare.go +++ b/internal/dnsclients/provider_cloud_flare.go @@ -13,7 +13,6 @@ import ( "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -270,7 +269,7 @@ func (this *CloudFlareProvider) doAPI(method string, apiPath string, args map[st _ = resp.Body.Close() }() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/internal/dnsclients/provider_custom_http.go b/internal/dnsclients/provider_custom_http.go index e99bde8c..01d8f1a3 100644 --- a/internal/dnsclients/provider_custom_http.go +++ b/internal/dnsclients/provider_custom_http.go @@ -10,7 +10,7 @@ import ( "github.com/TeaOSLab/EdgeAPI/internal/dnsclients/dnstypes" "github.com/TeaOSLab/EdgeAPI/internal/errors" "github.com/iwind/TeaGo/maps" - "io/ioutil" + "io" "net/http" "strconv" "time" @@ -180,5 +180,5 @@ func (this *CustomHTTPProvider) post(params maps.Map) (respData []byte, err erro if resp.StatusCode != 200 { return nil, errors.New("status should be 200, but got '" + strconv.Itoa(resp.StatusCode) + "'") } - return ioutil.ReadAll(resp.Body) + return io.ReadAll(resp.Body) } diff --git a/internal/dnsclients/provider_dnspod.go b/internal/dnsclients/provider_dnspod.go index e47930b8..c42ea2be 100644 --- a/internal/dnsclients/provider_dnspod.go +++ b/internal/dnsclients/provider_dnspod.go @@ -8,7 +8,7 @@ import ( "github.com/TeaOSLab/EdgeAPI/internal/utils/numberutils" "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -276,7 +276,7 @@ func (this *DNSPodProvider) post(path string, params map[string]string) (maps.Ma defer func() { _ = resp.Body.Close() }() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/internal/dnsclients/provider_huawei_dns.go b/internal/dnsclients/provider_huawei_dns.go index c641d0d1..d2726dfc 100644 --- a/internal/dnsclients/provider_huawei_dns.go +++ b/internal/dnsclients/provider_huawei_dns.go @@ -15,7 +15,6 @@ import ( "github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/types" "io" - "io/ioutil" "net/http" "net/url" "sort" @@ -1502,7 +1501,7 @@ func (this *HuaweiDNSProvider) doAPI(method string, apiPath string, args map[str _ = resp.Body.Close() }() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/internal/iplibrary/ip2Region.go b/internal/iplibrary/ip2Region.go index cbb77aa8..484ee7da 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/nodes/api_node.go b/internal/nodes/api_node.go index 0c485994..47a2749e 100644 --- a/internal/nodes/api_node.go +++ b/internal/nodes/api_node.go @@ -27,7 +27,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" "gopkg.in/yaml.v3" - "io/ioutil" "log" "net" "os" @@ -313,7 +312,7 @@ func (this *APINode) autoUpgrade() error { // 执行SQL var config = &dbs.Config{} - configData, err := ioutil.ReadFile(Tea.ConfigFile("db.yaml")) + configData, err := os.ReadFile(Tea.ConfigFile("db.yaml")) if err != nil { return errors.New("read database config file failed: " + err.Error()) } @@ -785,6 +784,6 @@ func (this *APINode) dbIssueSuggestion(errString string) string { func (this *APINode) saveIssues() { issuesJSON, err := json.Marshal(this.issues) if err == nil { - _ = ioutil.WriteFile(this.issuesFile, issuesJSON, 0666) + _ = os.WriteFile(this.issuesFile, issuesJSON, 0666) } } diff --git a/internal/nodes/rest_server.go b/internal/nodes/rest_server.go index 5672e19a..b620f5f6 100644 --- a/internal/nodes/rest_server.go +++ b/internal/nodes/rest_server.go @@ -8,7 +8,7 @@ import ( "github.com/TeaOSLab/EdgeAPI/internal/rpc/services" rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils" "github.com/iwind/TeaGo/maps" - "io/ioutil" + "io" "net" "net/http" "reflect" @@ -152,7 +152,7 @@ func (this *RestServer) handle(writer http.ResponseWriter, req *http.Request) { } // TODO 需要防止BODY过大攻击 - body, err := ioutil.ReadAll(req.Body) + body, err := io.ReadAll(req.Body) if err != nil { writer.WriteHeader(http.StatusBadRequest) _, _ = writer.Write([]byte(err.Error())) diff --git a/internal/setup/setup.go b/internal/setup/setup.go index 1a6b5134..f5c2d006 100644 --- a/internal/setup/setup.go +++ b/internal/setup/setup.go @@ -11,7 +11,6 @@ import ( "github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/types" "gopkg.in/yaml.v3" - "io/ioutil" "os" "strconv" "strings" @@ -75,7 +74,7 @@ func (this *Setup) Run() error { // 执行SQL config := &dbs.Config{} - configData, err := ioutil.ReadFile(Tea.ConfigFile("db.yaml")) + configData, err := os.ReadFile(Tea.ConfigFile("db.yaml")) if err != nil { return err } diff --git a/internal/setup/sql_executor.go b/internal/setup/sql_executor.go index 538e5f56..13fa1d6c 100644 --- a/internal/setup/sql_executor.go +++ b/internal/setup/sql_executor.go @@ -15,7 +15,7 @@ import ( "github.com/iwind/TeaGo/types" stringutil "github.com/iwind/TeaGo/utils/string" "gopkg.in/yaml.v3" - "io/ioutil" + "os" "time" ) @@ -35,7 +35,7 @@ func NewSQLExecutor(dbConfig *dbs.DBConfig) *SQLExecutor { func NewSQLExecutorFromCmd() (*SQLExecutor, error) { // 执行SQL config := &dbs.Config{} - configData, err := ioutil.ReadFile(Tea.ConfigFile("db.yaml")) + configData, err := os.ReadFile(Tea.ConfigFile("db.yaml")) if err != nil { return nil, err } diff --git a/internal/tasks/ssl_cert_update_ocsp_task.go b/internal/tasks/ssl_cert_update_ocsp_task.go index fb9e464f..7f35292f 100644 --- a/internal/tasks/ssl_cert_update_ocsp_task.go +++ b/internal/tasks/ssl_cert_update_ocsp_task.go @@ -15,7 +15,7 @@ import ( "github.com/TeaOSLab/EdgeAPI/internal/utils" "github.com/iwind/TeaGo/dbs" "golang.org/x/crypto/ocsp" - "io/ioutil" + "io" "net/http" "time" ) @@ -147,7 +147,7 @@ func (this *SSLCertUpdateOCSPTask) UpdateCertOCSP(certOne *models.SSLCert) (ocsp _ = issuerResp.Body.Close() }() - issuerData, err := ioutil.ReadAll(issuerResp.Body) + issuerData, err := io.ReadAll(issuerResp.Body) if err != nil { return nil, 0, errors.New("read issuer certificate failed: '" + issuerURL + "': " + err.Error()) } @@ -178,7 +178,7 @@ func (this *SSLCertUpdateOCSPTask) UpdateCertOCSP(certOne *models.SSLCert) (ocsp _ = ocspResp.Body.Close() }() - respData, err := ioutil.ReadAll(ocspResp.Body) + respData, err := io.ReadAll(ocspResp.Body) if err != nil { return nil, 0, errors.New("read ocsp failed: '" + ocspServerURL + "': " + err.Error()) } diff --git a/internal/utils/http.go b/internal/utils/http.go index de26d231..64543bac 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/service_linux.go b/internal/utils/service_linux.go index 3eaaa747..339a6ecd 100644 --- a/internal/utils/service_linux.go +++ b/internal/utils/service_linux.go @@ -7,7 +7,6 @@ import ( teaconst "github.com/TeaOSLab/EdgeAPI/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 }