chore: remove refs to deprecated io/ioutil (#1593)

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
This commit is contained in:
guangwu 2023-11-16 16:27:00 +08:00 committed by GitHub
parent c59825f3a5
commit 4577868567
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 19 additions and 24 deletions

View file

@ -2,7 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"strconv" "strconv"
"time" "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. // 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 { if err != nil {
app.log.Printf("error reading ses notification body: %v", err) app.log.Printf("error reading ses notification body: %v", err)
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.Ts("globals.messages.internalError")) return echo.NewHTTPError(http.StatusBadRequest, app.i18n.Ts("globals.messages.internalError"))

View file

@ -3,7 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"io" "io"
"io/ioutil" "os"
"net/http" "net/http"
"strings" "strings"
@ -66,7 +66,7 @@ func handleImportSubscribers(c echo.Context) error {
} }
defer src.Close() defer src.Close()
out, err := ioutil.TempFile("", "listmonk") out, err := os.CreateTemp("", "listmonk")
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.Ts("import.errorCopyingFile", "error", err.Error())) app.i18n.Ts("import.errorCopyingFile", "error", err.Error()))

View file

@ -3,7 +3,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"regexp" "regexp"
"strings" "strings"
@ -224,7 +223,7 @@ func newConfigFile(path string) error {
ReplaceAll(b, []byte(fmt.Sprintf(`admin_password = "%s"`, pwd))) 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. // checkSchema checks if the DB schema is installed.

View file

@ -2,7 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"io/ioutil" "io"
"net/http" "net/http"
"regexp" "regexp"
"runtime" "runtime"
@ -244,7 +244,7 @@ func handleTestSMTPSettings(c echo.Context) error {
app := c.Get("app").(*App) app := c.Get("app").(*App)
// Copy the raw JSON post body. // Copy the raw JSON post body.
reqBody, err := ioutil.ReadAll(c.Request().Body) reqBody, err := io.ReadAll(c.Request().Body)
if err != nil { if err != nil {
app.log.Printf("error reading SMTP test: %v", err) app.log.Printf("error reading SMTP test: %v", err)
return echo.NewHTTPError(http.StatusBadRequest, app.i18n.Ts("globals.messages.internalError")) return echo.NewHTTPError(http.StatusBadRequest, app.i18n.Ts("globals.messages.internalError"))

View file

@ -3,7 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/textproto" "net/textproto"
"strings" "strings"
@ -49,7 +49,7 @@ func handleSendTxMessage(c echo.Context) error {
} }
defer file.Close() defer file.Close()
b, err := ioutil.ReadAll(file) b, err := io.ReadAll(file)
if err != nil { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.Ts("globals.messages.invalidFields", "name", fmt.Sprintf("file: %s", err.Error()))) app.i18n.Ts("globals.messages.invalidFields", "name", fmt.Sprintf("file: %s", err.Error())))

View file

@ -2,7 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"io/ioutil" "io"
"net/http" "net/http"
"regexp" "regexp"
"time" "time"
@ -48,7 +48,7 @@ func checkUpdates(curVersion string, interval time.Duration, app *App) {
continue continue
} }
b, err := ioutil.ReadAll(resp.Body) b, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
app.log.Printf("error reading remote update payload: %v", err) app.log.Printf("error reading remote update payload: %v", err)
continue continue

View file

@ -8,7 +8,7 @@ import (
"encoding/pem" "encoding/pem"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"regexp" "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) 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 { if err != nil {
return nil, err return nil, err
} }

View file

@ -3,7 +3,7 @@ package captcha
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -58,7 +58,7 @@ func (c *Captcha) Verify(token string) (error, bool) {
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return err, false return err, false
} }

View file

@ -4,7 +4,6 @@ import (
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -67,7 +66,7 @@ func (c *Client) GetURL(name string) string {
// GetBlob accepts a URL, reads the file, and returns the blob. // GetBlob accepts a URL, reads the file, and returns the blob.
func (c *Client) GetBlob(url string) ([]byte, error) { 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 return b, err
} }

View file

@ -3,7 +3,6 @@ package s3
import ( import (
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/url" "net/url"
"path/filepath" "path/filepath"
"strings" "strings"
@ -123,7 +122,7 @@ func (c *Client) GetBlob(uurl string) ([]byte, error) {
return nil, err return nil, err
} }
b, err := ioutil.ReadAll(file) b, err := io.ReadAll(file)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -5,7 +5,6 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"net/textproto" "net/textproto"
"time" "time"
@ -197,7 +196,7 @@ func (p *Postback) exec(method, rURL string, reqBody []byte, headers http.Header
} }
defer func() { defer func() {
// Drain and close the body to let the Transport reuse the connection // 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() r.Body.Close()
}() }()

View file

@ -15,7 +15,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"net/mail" "net/mail"
"os" "os"
@ -377,7 +376,7 @@ func (s *Session) ExtractZIP(srcPath string, maxCSVs int) (string, []string, err
defer z.Close() defer z.Close()
// Create a temporary directory to extract the files. // Create a temporary directory to extract the files.
dir, err := ioutil.TempDir("", "listmonk") dir, err := os.MkdirTemp("", "listmonk")
if err != nil { if err != nil {
s.log.Printf("error creating temporary directory for extracting ZIP: %v", err) s.log.Printf("error creating temporary directory for extracting ZIP: %v", err)
return "", nil, err return "", nil, err