replace deprecated functions

This commit is contained in:
Louis Abel 2024-06-09 20:27:38 -07:00
parent 1fe2f9d2a3
commit 4ac60f8a74
Signed by: label
GPG Key ID: 3331F061D1D9990E
3 changed files with 7 additions and 8 deletions

View File

@ -3,7 +3,7 @@ package paste
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"os" "os"
"github.com/rocky-linux/rpaste/modules/utility" "github.com/rocky-linux/rpaste/modules/utility"
@ -43,7 +43,7 @@ func runPaste(ctx *cli.Context) error {
if stdMethod && PasteData == "" { if stdMethod && PasteData == "" {
fio, err := os.Stdin.Stat() fio, err := os.Stdin.Stat()
if (fio.Mode() & os.ModeCharDevice) == 0 { if (fio.Mode() & os.ModeCharDevice) == 0 {
bytes, _ := ioutil.ReadAll(os.Stdin) bytes, _ := io.ReadAll(os.Stdin)
PasteData = string(bytes) PasteData = string(bytes)
} else if err != nil { } else if err != nil {
fmt.Printf("Could not read from stdin: (%s)\n", err) fmt.Printf("Could not read from stdin: (%s)\n", err)
@ -65,7 +65,7 @@ func runPaste(ctx *cli.Context) error {
checkfile, _ := utility.IsFile(lastArg) checkfile, _ := utility.IsFile(lastArg)
// if it's a file, send it to the PasteData var // if it's a file, send it to the PasteData var
if checkfile { if checkfile {
fileBytes, err := ioutil.ReadFile(lastArg) fileBytes, err := os.ReadFile(lastArg)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -3,7 +3,7 @@ package paste
import ( import (
"bytes" "bytes"
"io/ioutil" "os"
"os/exec" "os/exec"
"regexp" "regexp"
"strconv" "strconv"
@ -96,14 +96,14 @@ func cpuInfo() string {
func support64Bit() string { func support64Bit() string {
text := " lm " text := " lm "
file, _ := ioutil.ReadFile("/proc/cpuinfo") file, _ := os.ReadFile("/proc/cpuinfo")
string := string(file) string := string(file)
return strconv.FormatBool(strings.Contains(string, text)) return strconv.FormatBool(strings.Contains(string, text))
} }
func virtSupport() string { func virtSupport() string {
re, _ := regexp.Compile(`(vmx|svm)`) re, _ := regexp.Compile(`(vmx|svm)`)
file, _ := ioutil.ReadFile("/proc/cpuinfo") file, _ := os.ReadFile("/proc/cpuinfo")
exists := re.Match(file) exists := re.Match(file)
return strconv.FormatBool(exists) return strconv.FormatBool(exists)
} }

View File

@ -5,7 +5,6 @@ package utility
import ( import (
_ "errors" _ "errors"
"io/ioutil"
"os" "os"
_ "path" _ "path"
_ "path/filepath" _ "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 // Reads one-line text files (like for /sys or /proc) - Strips carriage returns
func Slurp(path string) string { func Slurp(path string) string {
data, err := ioutil.ReadFile(path) data, err := os.ReadFile(path)
if err != nil { if err != nil {
return "" return ""
} }