From 45778685677a1777a54392febc25181e85839f3a Mon Sep 17 00:00:00 2001 From: guangwu Date: Thu, 16 Nov 2023 16:27:00 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil (#1593) Signed-off-by: guoguangwu --- cmd/bounce.go | 4 ++-- cmd/import.go | 4 ++-- cmd/install.go | 3 +-- cmd/settings.go | 4 ++-- cmd/tx.go | 4 ++-- cmd/updates.go | 4 ++-- internal/bounce/webhooks/ses.go | 4 ++-- internal/captcha/captcha.go | 4 ++-- internal/media/providers/filesystem/filesystem.go | 3 +-- internal/media/providers/s3/s3.go | 3 +-- internal/messenger/postback/postback.go | 3 +-- internal/subimporter/importer.go | 3 +-- 12 files changed, 19 insertions(+), 24 deletions(-) diff --git a/cmd/bounce.go b/cmd/bounce.go index 6f418a41..7bf82011 100644 --- a/cmd/bounce.go +++ b/cmd/bounce.go @@ -2,7 +2,7 @@ package main import ( "encoding/json" - "io/ioutil" + "io" "net/http" "strconv" "time" @@ -121,7 +121,7 @@ func handleBounceWebhook(c echo.Context) error { ) // Read the request body instead of using c.Bind() to read to save the entire raw request as meta. - rawReq, err := ioutil.ReadAll(c.Request().Body) + rawReq, err := io.ReadAll(c.Request().Body) if err != nil { app.log.Printf("error reading ses notification body: %v", err) return echo.NewHTTPError(http.StatusBadRequest, app.i18n.Ts("globals.messages.internalError")) diff --git a/cmd/import.go b/cmd/import.go index 9d30a66f..42dde37c 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "io" - "io/ioutil" + "os" "net/http" "strings" @@ -66,7 +66,7 @@ func handleImportSubscribers(c echo.Context) error { } defer src.Close() - out, err := ioutil.TempFile("", "listmonk") + out, err := os.CreateTemp("", "listmonk") if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, app.i18n.Ts("import.errorCopyingFile", "error", err.Error())) diff --git a/cmd/install.go b/cmd/install.go index 5e39a879..3dce0541 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -3,7 +3,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "os" "regexp" "strings" @@ -224,7 +223,7 @@ func newConfigFile(path string) error { ReplaceAll(b, []byte(fmt.Sprintf(`admin_password = "%s"`, pwd))) } - return ioutil.WriteFile(path, b, 0644) + return os.WriteFile(path, b, 0644) } // checkSchema checks if the DB schema is installed. diff --git a/cmd/settings.go b/cmd/settings.go index 421f4b76..7c0f0d57 100644 --- a/cmd/settings.go +++ b/cmd/settings.go @@ -2,7 +2,7 @@ package main import ( "bytes" - "io/ioutil" + "io" "net/http" "regexp" "runtime" @@ -244,7 +244,7 @@ func handleTestSMTPSettings(c echo.Context) error { app := c.Get("app").(*App) // Copy the raw JSON post body. - reqBody, err := ioutil.ReadAll(c.Request().Body) + reqBody, err := io.ReadAll(c.Request().Body) if err != nil { app.log.Printf("error reading SMTP test: %v", err) return echo.NewHTTPError(http.StatusBadRequest, app.i18n.Ts("globals.messages.internalError")) diff --git a/cmd/tx.go b/cmd/tx.go index 7b4c869f..743fcba2 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -3,7 +3,7 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/textproto" "strings" @@ -49,7 +49,7 @@ func handleSendTxMessage(c echo.Context) error { } defer file.Close() - b, err := ioutil.ReadAll(file) + b, err := io.ReadAll(file) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, app.i18n.Ts("globals.messages.invalidFields", "name", fmt.Sprintf("file: %s", err.Error()))) diff --git a/cmd/updates.go b/cmd/updates.go index af52b673..3f792a3b 100644 --- a/cmd/updates.go +++ b/cmd/updates.go @@ -2,7 +2,7 @@ package main import ( "encoding/json" - "io/ioutil" + "io" "net/http" "regexp" "time" @@ -48,7 +48,7 @@ func checkUpdates(curVersion string, interval time.Duration, app *App) { continue } - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { app.log.Printf("error reading remote update payload: %v", err) continue diff --git a/internal/bounce/webhooks/ses.go b/internal/bounce/webhooks/ses.go index 536ae673..387b6178 100644 --- a/internal/bounce/webhooks/ses.go +++ b/internal/bounce/webhooks/ses.go @@ -8,7 +8,7 @@ import ( "encoding/pem" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "regexp" @@ -239,7 +239,7 @@ func (s *SES) getCert(certURL string) (*x509.Certificate, error) { return nil, fmt.Errorf("invalid SNS certificate URL: %v", u.Host) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/internal/captcha/captcha.go b/internal/captcha/captcha.go index a6ab4414..fd39cfa2 100644 --- a/internal/captcha/captcha.go +++ b/internal/captcha/captcha.go @@ -3,7 +3,7 @@ package captcha import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "strings" @@ -58,7 +58,7 @@ func (c *Captcha) Verify(token string) (error, bool) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return err, false } diff --git a/internal/media/providers/filesystem/filesystem.go b/internal/media/providers/filesystem/filesystem.go index c2e6b1b7..a1e0afd5 100644 --- a/internal/media/providers/filesystem/filesystem.go +++ b/internal/media/providers/filesystem/filesystem.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -67,7 +66,7 @@ func (c *Client) GetURL(name string) string { // GetBlob accepts a URL, reads the file, and returns the blob. func (c *Client) GetBlob(url string) ([]byte, error) { - b, err := ioutil.ReadFile(filepath.Join(getDir(c.opts.UploadPath), filepath.Base(url))) + b, err := os.ReadFile(filepath.Join(getDir(c.opts.UploadPath), filepath.Base(url))) return b, err } diff --git a/internal/media/providers/s3/s3.go b/internal/media/providers/s3/s3.go index a05ecd8a..2bf7eee0 100644 --- a/internal/media/providers/s3/s3.go +++ b/internal/media/providers/s3/s3.go @@ -3,7 +3,6 @@ package s3 import ( "fmt" "io" - "io/ioutil" "net/url" "path/filepath" "strings" @@ -123,7 +122,7 @@ func (c *Client) GetBlob(uurl string) ([]byte, error) { return nil, err } - b, err := ioutil.ReadAll(file) + b, err := io.ReadAll(file) if err != nil { return nil, err } diff --git a/internal/messenger/postback/postback.go b/internal/messenger/postback/postback.go index 736803d8..3cb6c798 100644 --- a/internal/messenger/postback/postback.go +++ b/internal/messenger/postback/postback.go @@ -5,7 +5,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "net/http" "net/textproto" "time" @@ -197,7 +196,7 @@ func (p *Postback) exec(method, rURL string, reqBody []byte, headers http.Header } defer func() { // Drain and close the body to let the Transport reuse the connection - io.Copy(ioutil.Discard, r.Body) + io.Copy(io.Discard, r.Body) r.Body.Close() }() diff --git a/internal/subimporter/importer.go b/internal/subimporter/importer.go index 17f1159d..943e5890 100644 --- a/internal/subimporter/importer.go +++ b/internal/subimporter/importer.go @@ -15,7 +15,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/mail" "os" @@ -377,7 +376,7 @@ func (s *Session) ExtractZIP(srcPath string, maxCSVs int) (string, []string, err defer z.Close() // Create a temporary directory to extract the files. - dir, err := ioutil.TempDir("", "listmonk") + dir, err := os.MkdirTemp("", "listmonk") if err != nil { s.log.Printf("error creating temporary directory for extracting ZIP: %v", err) return "", nil, err