From cf53730f6ccdaca90fdea69a1e313f13da363b3b Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Mon, 10 Jul 2023 17:55:04 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil --- account_import.go | 3 +-- activitypub.go | 6 +++--- app.go | 9 ++++----- keys.go | 3 +-- monetization.go | 4 ++-- oauth.go | 3 +-- templates.go | 5 ++--- updates.go | 4 ++-- webfinger.go | 4 ++-- 9 files changed, 18 insertions(+), 23 deletions(-) diff --git a/account_import.go b/account_import.go index b34f3a7..656852f 100644 --- a/account_import.go +++ b/account_import.go @@ -5,7 +5,6 @@ import ( "fmt" "html/template" "io" - "io/ioutil" "net/http" "os" "path/filepath" @@ -100,7 +99,7 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err } defer file.Close() - tempFile, err := ioutil.TempFile("", "post-upload-*.txt") + tempFile, err := os.CreateTemp("", "post-upload-*.txt") if err != nil { fileErrs = append(fileErrs, fmt.Errorf("Internal error for %s", formFile.Filename)) log.Error("import file: create temp file %s: %v", formFile.Filename, err) diff --git a/activitypub.go b/activitypub.go index efc34f3..597d129 100644 --- a/activitypub.go +++ b/activitypub.go @@ -17,7 +17,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httputil" "net/url" @@ -549,7 +549,7 @@ func makeActivityPost(hostName string, p *activitystreams.Person, url string, m defer resp.Body.Close() } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return err } @@ -601,7 +601,7 @@ func resolveIRI(hostName, url string) ([]byte, error) { defer resp.Body.Close() } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/app.go b/app.go index c7bdbb5..cd70475 100644 --- a/app.go +++ b/app.go @@ -16,7 +16,6 @@ import ( _ "embed" "fmt" "html/template" - "io/ioutil" "net" "net/http" "net/url" @@ -177,7 +176,7 @@ func (app *App) LoadKeys() error { executable = filepath.Base(executable) } - app.keys.EmailKey, err = ioutil.ReadFile(emailKeyPath) + app.keys.EmailKey, err = os.ReadFile(emailKeyPath) if err != nil { return err } @@ -185,7 +184,7 @@ func (app *App) LoadKeys() error { if debugging { log.Info(" %s", cookieAuthKeyPath) } - app.keys.CookieAuthKey, err = ioutil.ReadFile(cookieAuthKeyPath) + app.keys.CookieAuthKey, err = os.ReadFile(cookieAuthKeyPath) if err != nil { return err } @@ -193,7 +192,7 @@ func (app *App) LoadKeys() error { if debugging { log.Info(" %s", cookieKeyPath) } - app.keys.CookieKey, err = ioutil.ReadFile(cookieKeyPath) + app.keys.CookieKey, err = os.ReadFile(cookieKeyPath) if err != nil { return err } @@ -201,7 +200,7 @@ func (app *App) LoadKeys() error { if debugging { log.Info(" %s", csrfKeyPath) } - app.keys.CSRFKey, err = ioutil.ReadFile(csrfKeyPath) + app.keys.CSRFKey, err = os.ReadFile(csrfKeyPath) if err != nil { if os.IsNotExist(err) { log.Error(`Missing key: %s. diff --git a/keys.go b/keys.go index 98ff13f..7674995 100644 --- a/keys.go +++ b/keys.go @@ -13,7 +13,6 @@ package writefreely import ( "github.com/writeas/web-core/log" "github.com/writefreely/writefreely/key" - "io/ioutil" "os" "path/filepath" ) @@ -65,7 +64,7 @@ func generateKey(path string) error { log.Error("FAILED. %s. Run writefreely --gen-keys again.", err) return err } - err = ioutil.WriteFile(path, b, 0600) + err = os.WriteFile(path, b, 0600) if err != nil { log.Error("FAILED writing file: %s", err) return err diff --git a/monetization.go b/monetization.go index 3bb4fcf..4d6b42b 100644 --- a/monetization.go +++ b/monetization.go @@ -16,7 +16,7 @@ import ( "github.com/gorilla/mux" "github.com/writeas/impart" "github.com/writeas/web-core/log" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -144,7 +144,7 @@ func verifyReceipt(receipt, id string) error { defer resp.Body.Close() } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { log.Error("Unable to read %s response body: %s", receiptsHost, err) return err diff --git a/oauth.go b/oauth.go index ee08740..06a2d20 100644 --- a/oauth.go +++ b/oauth.go @@ -15,7 +15,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strings" @@ -450,7 +449,7 @@ func (r *callbackProxyClient) register(ctx context.Context, state string) error func limitedJsonUnmarshal(body io.ReadCloser, n int, thing interface{}) error { lr := io.LimitReader(body, int64(n+1)) - data, err := ioutil.ReadAll(lr) + data, err := io.ReadAll(lr) if err != nil { return err } diff --git a/templates.go b/templates.go index e51317b..3bb7d13 100644 --- a/templates.go +++ b/templates.go @@ -14,9 +14,8 @@ import ( "errors" "html/template" "io" - "io/ioutil" - "net/http" "os" + "net/http" "path/filepath" "strings" @@ -120,7 +119,7 @@ func initUserPage(parentDir, path, key string) { // InitTemplates loads all template files from the configured parent dir. func InitTemplates(cfg *config.Config) error { log.Info("Loading templates...") - tmplFiles, err := ioutil.ReadDir(filepath.Join(cfg.Server.TemplatesParentDir, templatesDir)) + tmplFiles, err := os.ReadDir(filepath.Join(cfg.Server.TemplatesParentDir, templatesDir)) if err != nil { return err } diff --git a/updates.go b/updates.go index 574a91c..e29e13b 100644 --- a/updates.go +++ b/updates.go @@ -12,7 +12,7 @@ package writefreely import ( "github.com/writeas/web-core/log" - "io/ioutil" + "io" "net/http" "strings" "sync" @@ -121,7 +121,7 @@ func newVersionCheck() (string, error) { if err == nil && res.StatusCode == http.StatusOK { defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) if err != nil { return "", err } diff --git a/webfinger.go b/webfinger.go index 023c8a5..0c52f72 100644 --- a/webfinger.go +++ b/webfinger.go @@ -12,7 +12,7 @@ package writefreely import ( "encoding/json" - "io/ioutil" + "io" "net/http" "strings" @@ -110,7 +110,7 @@ func RemoteLookup(handle string) string { return "" } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { log.Error("Error on webfinger response: %v", err) return ""