remove refs to deprecated io/ioutil

This commit is contained in:
nikk gitanes
2023-07-10 03:14:53 +03:00
parent 4c41f7ddcc
commit 1d875b57b2
8 changed files with 18 additions and 20 deletions

View File

@@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@@ -127,7 +126,7 @@ func watchTDir(dir string) {
path = dir path = dir
} }
for { for {
files, err := ioutil.ReadDir(path) files, err := os.ReadDir(path)
if err == nil { if err == nil {
for _, file := range files { for _, file := range files {
filename := filepath.Join(path, file.Name()) filename := filepath.Join(path, file.Name())

View File

@@ -3,7 +3,7 @@ package log
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"os" "os"
"strings" "strings"
@@ -93,8 +93,8 @@ func WebLogger() gin.HandlerFunc {
body := "" body := ""
// save body if not form or file // save body if not form or file
if !strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data") { if !strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data") {
body, _ := ioutil.ReadAll(c.Request.Body) body, _ := io.ReadAll(c.Request.Body)
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) c.Request.Body = io.NopCloser(bytes.NewBuffer(body))
} else { } else {
body = "body hidden, too large" body = "body hidden, too large"
} }

View File

@@ -1,7 +1,6 @@
package server package server
import ( import (
"io/ioutil"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@@ -36,7 +35,7 @@ func cleanCache() {
return return
} }
dirs, err := ioutil.ReadDir(settings.BTsets.TorrentsSavePath) dirs, err := os.ReadDir(settings.BTsets.TorrentsSavePath)
if err != nil { if err != nil {
return return
} }
@@ -68,7 +67,7 @@ func cleanCache() {
} }
func removeAllFiles(path string) { func removeAllFiles(path string) {
files, err := ioutil.ReadDir(path) files, err := os.ReadDir(path)
if err != nil { if err != nil {
return return
} }

View File

@@ -2,7 +2,6 @@ package torr
import ( import (
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@@ -143,7 +142,7 @@ func RemTorrent(hashHex string) {
hash := metainfo.NewHashFromHex(hashHex) hash := metainfo.NewHashFromHex(hashHex)
if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" { if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" {
name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex) name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex)
ff, _ := ioutil.ReadDir(name) ff, _ := os.ReadDir(name)
for _, f := range ff { for _, f := range ff {
os.Remove(filepath.Join(name, f.Name())) os.Remove(filepath.Join(name, f.Name()))
} }

View File

@@ -2,7 +2,7 @@ package utils
import ( import (
"bufio" "bufio"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -12,7 +12,7 @@ import (
) )
func ReadBlockedIP() (ranger iplist.Ranger, err error) { 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 { if err != nil {
return nil, err return nil, err
} }

View File

@@ -2,9 +2,10 @@ package utils
import ( import (
"encoding/base32" "encoding/base32"
"io/ioutil" "io"
"math/rand" "math/rand"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -34,7 +35,7 @@ var loadedTrackers []string
func GetTrackerFromFile() []string { func GetTrackerFromFile() []string {
name := filepath.Join(settings.Path, "trackers.txt") name := filepath.Join(settings.Path, "trackers.txt")
buf, err := ioutil.ReadFile(name) buf, err := os.ReadFile(name)
if err == nil { if err == nil {
list := strings.Split(string(buf), "\n") list := strings.Split(string(buf), "\n")
var ret []string var ret []string
@@ -62,7 +63,7 @@ func loadNewTracker() {
} }
resp, err := http.Get("https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best_ip.txt") resp, err := http.Get("https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best_ip.txt")
if err == nil { if err == nil {
buf, err := ioutil.ReadAll(resp.Body) buf, err := io.ReadAll(resp.Body)
if err == nil { if err == nil {
arr := strings.Split(string(buf), "\n") arr := strings.Split(string(buf), "\n")
var ret []string var ret []string

View File

@@ -3,8 +3,8 @@ package auth
import ( import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"io/ioutil"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strings" "strings"
@@ -28,7 +28,7 @@ func SetupAuth(engine *gin.Engine) *gin.RouterGroup {
} }
func getAccounts() gin.Accounts { 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 { if err != nil {
return nil return nil
} }

View File

@@ -4,9 +4,9 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"errors" "errors"
"io/ioutil"
"net" "net"
"net/http" "net/http"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -22,11 +22,11 @@ func Blocker() gin.HandlerFunc {
} }
name := filepath.Join(settings.Path, "bip.txt") name := filepath.Join(settings.Path, "bip.txt")
buf, _ := ioutil.ReadFile(name) buf, _ := os.ReadFile(name)
blackIpList := scanBuf(buf) blackIpList := scanBuf(buf)
name = filepath.Join(settings.Path, "wip.txt") name = filepath.Join(settings.Path, "wip.txt")
buf, _ = ioutil.ReadFile(name) buf, _ = os.ReadFile(name)
whiteIpList := scanBuf(buf) whiteIpList := scanBuf(buf)
if blackIpList.NumRanges() == 0 && whiteIpList.NumRanges() == 0 { if blackIpList.NumRanges() == 0 && whiteIpList.NumRanges() == 0 {