From 4ac60f8a7475428bd9ead8f981ade0c431a78b43 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Sun, 9 Jun 2024 20:27:38 -0700 Subject: [PATCH] replace deprecated functions --- modules/paste/method.go | 6 +++--- modules/paste/sysinfo.go | 6 +++--- modules/utility/file.go | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/paste/method.go b/modules/paste/method.go index ac03dfd..4b04c5b 100644 --- a/modules/paste/method.go +++ b/modules/paste/method.go @@ -3,7 +3,7 @@ package paste import ( "fmt" - "io/ioutil" + "io" "os" "github.com/rocky-linux/rpaste/modules/utility" @@ -43,7 +43,7 @@ func runPaste(ctx *cli.Context) error { if stdMethod && PasteData == "" { fio, err := os.Stdin.Stat() if (fio.Mode() & os.ModeCharDevice) == 0 { - bytes, _ := ioutil.ReadAll(os.Stdin) + bytes, _ := io.ReadAll(os.Stdin) PasteData = string(bytes) } else if err != nil { fmt.Printf("Could not read from stdin: (%s)\n", err) @@ -65,7 +65,7 @@ func runPaste(ctx *cli.Context) error { checkfile, _ := utility.IsFile(lastArg) // if it's a file, send it to the PasteData var if checkfile { - fileBytes, err := ioutil.ReadFile(lastArg) + fileBytes, err := os.ReadFile(lastArg) if err != nil { panic(err) } diff --git a/modules/paste/sysinfo.go b/modules/paste/sysinfo.go index 206fa8c..7ecc8b2 100644 --- a/modules/paste/sysinfo.go +++ b/modules/paste/sysinfo.go @@ -3,7 +3,7 @@ package paste import ( "bytes" - "io/ioutil" + "os" "os/exec" "regexp" "strconv" @@ -96,14 +96,14 @@ func cpuInfo() string { func support64Bit() string { text := " lm " - file, _ := ioutil.ReadFile("/proc/cpuinfo") + file, _ := os.ReadFile("/proc/cpuinfo") string := string(file) return strconv.FormatBool(strings.Contains(string, text)) } func virtSupport() string { re, _ := regexp.Compile(`(vmx|svm)`) - file, _ := ioutil.ReadFile("/proc/cpuinfo") + file, _ := os.ReadFile("/proc/cpuinfo") exists := re.Match(file) return strconv.FormatBool(exists) } diff --git a/modules/utility/file.go b/modules/utility/file.go index bebd0ea..f4aa888 100644 --- a/modules/utility/file.go +++ b/modules/utility/file.go @@ -5,7 +5,6 @@ package utility import ( _ "errors" - "io/ioutil" "os" _ "path" _ "path/filepath" @@ -38,7 +37,7 @@ func IsExist(path string) (bool, error) { // Reads one-line text files (like for /sys or /proc) - Strips carriage returns func Slurp(path string) string { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return "" }