refactor: replace deprecated I/O APIs

This commit is contained in:
Yanislav Igonin 2026-07-15 23:27:41 +04:00
parent 2b98b9a55a
commit e3d1c05558
3 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,6 @@
package build package build
import ( import (
"io/ioutil"
"math/rand" "math/rand"
"os" "os"
"strings" "strings"
@ -10,7 +9,7 @@ import (
// Gets file paths from directory recursively. // Gets file paths from directory recursively.
func getFilePathsRecursively(dir string) ([]string, error) { func getFilePathsRecursively(dir string) ([]string, error) {
var paths []string var paths []string
files, err := ioutil.ReadDir(dir) files, err := os.ReadDir(dir)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -32,7 +31,7 @@ func getFilePathsRecursively(dir string) ([]string, error) {
// Returns all css files paths in ../static/styles folder. // Returns all css files paths in ../static/styles folder.
func getCssFilesPaths() []string { func getCssFilesPaths() []string {
var paths []string var paths []string
files, err := ioutil.ReadDir("static/styles") files, err := os.ReadDir("static/styles")
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -99,7 +98,7 @@ func RenameCss() {
} }
for _, htmlTemplatePath := range htmlTemplatePaths { for _, htmlTemplatePath := range htmlTemplatePaths {
htmlTemplate, err := ioutil.ReadFile(htmlTemplatePath) htmlTemplate, err := os.ReadFile(htmlTemplatePath)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -108,7 +107,7 @@ func RenameCss() {
htmlTemplate = []byte(strings.Replace(string(htmlTemplate), origPath, newPath, -1)) htmlTemplate = []byte(strings.Replace(string(htmlTemplate), origPath, newPath, -1))
} }
// write html template to file // write html template to file
err = ioutil.WriteFile(htmlTemplatePath, htmlTemplate, 0644) err = os.WriteFile(htmlTemplatePath, htmlTemplate, 0644)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -1,7 +1,6 @@
package files package files
import ( import (
"io/ioutil"
"log" "log"
"os" "os"
"path" "path"
@ -15,7 +14,7 @@ func GetFullFilePathsInFolder(folder string) []string {
} }
fullFolderPath := path.Join(currentPath, folder) fullFolderPath := path.Join(currentPath, folder)
files, err := ioutil.ReadDir(fullFolderPath) files, err := os.ReadDir(fullFolderPath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -31,7 +30,7 @@ func GetFullFilePathsInFolder(folder string) []string {
// Reads file contents by full path and returns string // Reads file contents by full path and returns string
func ReadFileText(fullFilePath string) string { func ReadFileText(fullFilePath string) string {
file, err := ioutil.ReadFile(fullFilePath) file, err := os.ReadFile(fullFilePath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -3,7 +3,7 @@ package gateway
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/ioutil" "io"
"log" "log"
"net/http" "net/http"
@ -29,8 +29,9 @@ func Connect() {
if err != nil { if err != nil {
log.Panicln(err) log.Panicln(err)
} }
defer resp.Body.Close()
//We Read the response body on the line below. //We Read the response body on the line below.
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
log.Panicln(err) log.Panicln(err)
} }