From 1d875b57b2ec9768ba0484fedf102e73a9346306 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Mon, 10 Jul 2023 03:14:53 +0300 Subject: [PATCH] remove refs to deprecated io/ioutil --- server/cmd/main.go | 3 +-- server/log/log.go | 6 +++--- server/server.go | 5 ++--- server/torr/apihelper.go | 3 +-- server/torr/utils/blockedIP.go | 4 ++-- server/torr/utils/torrent.go | 7 ++++--- server/web/auth/auth.go | 4 ++-- server/web/blocker/blocker.go | 6 +++--- 8 files changed, 18 insertions(+), 20 deletions(-) diff --git a/server/cmd/main.go b/server/cmd/main.go index 10fab82..71c4d8e 100644 --- a/server/cmd/main.go +++ b/server/cmd/main.go @@ -3,7 +3,6 @@ package main import ( "context" "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -127,7 +126,7 @@ func watchTDir(dir string) { path = dir } for { - files, err := ioutil.ReadDir(path) + files, err := os.ReadDir(path) if err == nil { for _, file := range files { filename := filepath.Join(path, file.Name()) diff --git a/server/log/log.go b/server/log/log.go index c7ea035..64d796e 100644 --- a/server/log/log.go +++ b/server/log/log.go @@ -3,7 +3,7 @@ package log import ( "bytes" "fmt" - "io/ioutil" + "io" "log" "os" "strings" @@ -93,8 +93,8 @@ func WebLogger() gin.HandlerFunc { body := "" // save body if not form or file if !strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data") { - body, _ := ioutil.ReadAll(c.Request.Body) - c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) + body, _ := io.ReadAll(c.Request.Body) + c.Request.Body = io.NopCloser(bytes.NewBuffer(body)) } else { body = "body hidden, too large" } diff --git a/server/server.go b/server/server.go index 8aebb3d..4b3df32 100644 --- a/server/server.go +++ b/server/server.go @@ -1,7 +1,6 @@ package server import ( - "io/ioutil" "net" "os" "path/filepath" @@ -36,7 +35,7 @@ func cleanCache() { return } - dirs, err := ioutil.ReadDir(settings.BTsets.TorrentsSavePath) + dirs, err := os.ReadDir(settings.BTsets.TorrentsSavePath) if err != nil { return } @@ -68,7 +67,7 @@ func cleanCache() { } func removeAllFiles(path string) { - files, err := ioutil.ReadDir(path) + files, err := os.ReadDir(path) if err != nil { return } diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 4e51299..1384ec0 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -2,7 +2,6 @@ package torr import ( "io" - "io/ioutil" "os" "path/filepath" "sort" @@ -143,7 +142,7 @@ func RemTorrent(hashHex string) { hash := metainfo.NewHashFromHex(hashHex) if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" { name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex) - ff, _ := ioutil.ReadDir(name) + ff, _ := os.ReadDir(name) for _, f := range ff { os.Remove(filepath.Join(name, f.Name())) } diff --git a/server/torr/utils/blockedIP.go b/server/torr/utils/blockedIP.go index 61edc04..fbe56b4 100644 --- a/server/torr/utils/blockedIP.go +++ b/server/torr/utils/blockedIP.go @@ -2,7 +2,7 @@ package utils import ( "bufio" - "io/ioutil" + "os" "path/filepath" "strings" @@ -12,7 +12,7 @@ import ( ) func ReadBlockedIP() (ranger iplist.Ranger, err error) { - buf, err := ioutil.ReadFile(filepath.Join(settings.Path, "blocklist")) + buf, err := os.ReadFile(filepath.Join(settings.Path, "blocklist")) if err != nil { return nil, err } diff --git a/server/torr/utils/torrent.go b/server/torr/utils/torrent.go index 9120f3f..006c585 100644 --- a/server/torr/utils/torrent.go +++ b/server/torr/utils/torrent.go @@ -2,9 +2,10 @@ package utils import ( "encoding/base32" - "io/ioutil" + "io" "math/rand" "net/http" + "os" "path/filepath" "strings" @@ -34,7 +35,7 @@ var loadedTrackers []string func GetTrackerFromFile() []string { name := filepath.Join(settings.Path, "trackers.txt") - buf, err := ioutil.ReadFile(name) + buf, err := os.ReadFile(name) if err == nil { list := strings.Split(string(buf), "\n") var ret []string @@ -62,7 +63,7 @@ func loadNewTracker() { } resp, err := http.Get("https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best_ip.txt") if err == nil { - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err == nil { arr := strings.Split(string(buf), "\n") var ret []string diff --git a/server/web/auth/auth.go b/server/web/auth/auth.go index 2b07c90..cb5eb08 100644 --- a/server/web/auth/auth.go +++ b/server/web/auth/auth.go @@ -3,8 +3,8 @@ package auth import ( "encoding/base64" "encoding/json" - "io/ioutil" "net/http" + "os" "path/filepath" "reflect" "strings" @@ -28,7 +28,7 @@ func SetupAuth(engine *gin.Engine) *gin.RouterGroup { } func getAccounts() gin.Accounts { - buf, err := ioutil.ReadFile(filepath.Join(settings.Path, "accs.db")) + buf, err := os.ReadFile(filepath.Join(settings.Path, "accs.db")) if err != nil { return nil } diff --git a/server/web/blocker/blocker.go b/server/web/blocker/blocker.go index 3ceecca..7bfbc10 100644 --- a/server/web/blocker/blocker.go +++ b/server/web/blocker/blocker.go @@ -4,9 +4,9 @@ import ( "bufio" "bytes" "errors" - "io/ioutil" "net" "net/http" + "os" "path/filepath" "strings" @@ -22,11 +22,11 @@ func Blocker() gin.HandlerFunc { } name := filepath.Join(settings.Path, "bip.txt") - buf, _ := ioutil.ReadFile(name) + buf, _ := os.ReadFile(name) blackIpList := scanBuf(buf) name = filepath.Join(settings.Path, "wip.txt") - buf, _ = ioutil.ReadFile(name) + buf, _ = os.ReadFile(name) whiteIpList := scanBuf(buf) if blackIpList.NumRanges() == 0 && whiteIpList.NumRanges() == 0 {