From 3dccbd602c225d1dc1cd10226e9724f70190b83b Mon Sep 17 00:00:00 2001 From: handlerug Date: Fri, 2 Jul 2021 15:29:55 +0700 Subject: [PATCH] Migrate away from ioutil --- hyphae/files.go | 4 ++-- shroom/upload.go | 6 +++--- shroom/view.go | 5 ++--- web/readers.go | 3 +-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/hyphae/files.go b/hyphae/files.go index 082a6df..175bc19 100644 --- a/hyphae/files.go +++ b/hyphae/files.go @@ -1,8 +1,8 @@ package hyphae import ( - "io/ioutil" "log" + "os" "path/filepath" "github.com/bouncepaw/mycorrhiza/mimetype" @@ -33,7 +33,7 @@ func Index(path string) { // indexHelper finds all hypha files in the full `path` and sends them to the channel. Handling of duplicate entries and attachment and counting them is up to the caller. func indexHelper(path string, nestLevel uint, ch chan *Hypha) { - nodes, err := ioutil.ReadDir(path) + nodes, err := os.ReadDir(path) if err != nil { log.Fatal(err) } diff --git a/shroom/upload.go b/shroom/upload.go index 55887f7..e84e93e 100644 --- a/shroom/upload.go +++ b/shroom/upload.go @@ -3,7 +3,7 @@ package shroom import ( "errors" "fmt" - "io/ioutil" + "io" "log" "mime/multipart" "os" @@ -45,7 +45,7 @@ func UploadText(h *hyphae.Hypha, data []byte, message string, u *user.User) (hop func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.User) (*history.HistoryOp, string) { var ( hop = history.Operation(history.TypeEditBinary).WithMsg(fmt.Sprintf("Upload binary part for ā€˜%sā€™ with type ā€˜%sā€™", h.Name, mime)) - data, err = ioutil.ReadAll(file) + data, err = io.ReadAll(file) ) if err != nil { @@ -80,7 +80,7 @@ func uploadHelp(h *hyphae.Hypha, hop *history.HistoryOp, ext string, data []byte return hop.WithErrAbort(err), err.Error() } - if err := ioutil.WriteFile(fullPath, data, 0666); err != nil { + if err := os.WriteFile(fullPath, data, 0666); err != nil { return hop.WithErrAbort(err), err.Error() } diff --git a/shroom/view.go b/shroom/view.go index ce7a8f4..486c479 100644 --- a/shroom/view.go +++ b/shroom/view.go @@ -1,7 +1,6 @@ package shroom import ( - "io/ioutil" "os" "github.com/bouncepaw/mycorrhiza/cfg" @@ -13,7 +12,7 @@ func FetchTextPart(h *hyphae.Hypha) (string, error) { if h.TextPath == "" { return "", nil } - text, err := ioutil.ReadFile(h.TextPath) + text, err := os.ReadFile(h.TextPath) if os.IsNotExist(err) { return "", nil } else if err != nil { @@ -26,7 +25,7 @@ func SetHeaderLinks() { if userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha); !userLinksHypha.Exists { cfg.SetDefaultHeaderLinks() } else { - contents, err := ioutil.ReadFile(userLinksHypha.TextPath) + contents, err := os.ReadFile(userLinksHypha.TextPath) if err != nil || len(contents) == 0 { cfg.SetDefaultHeaderLinks() } else { diff --git a/web/readers.go b/web/readers.go index a800adf..758f025 100644 --- a/web/readers.go +++ b/web/readers.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/bouncepaw/mycomarkup/mycocontext" "github.com/bouncepaw/mycorrhiza/cfg" - "io/ioutil" "log" "net/http" "os" @@ -123,7 +122,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) { u = user.FromRequest(rq) ) if h.Exists { - fileContentsT, errT := ioutil.ReadFile(h.TextPath) + fileContentsT, errT := os.ReadFile(h.TextPath) _, errB := os.Stat(h.BinaryPath) if errT == nil { ctx, _ := mycocontext.ContextFromStringInput(hyphaName, string(fileContentsT))