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

View File

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

View File

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