From 55b85b9cac07a1c95195e00d038e893112f9c879 Mon Sep 17 00:00:00 2001 From: Mathieu Deous Date: Thu, 5 Jan 2023 21:58:12 +0100 Subject: Update deprecated funcs and gh actions (#123) * migrate deprecated functions * update github actions--- main.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index d5f8d69..de64b90 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "log" "net/http" "os" @@ -103,7 +102,7 @@ func handleError(err error, desc string, isFatal bool) { // returns its location. func writeRulesFiles(content fs.FS) string { // create temporary folder structure - rulesPath, err := ioutil.TempDir(os.TempDir(), TempDirPrefix) + rulesPath, err := os.MkdirTemp(os.TempDir(), TempDirPrefix) handleError(err, "unable to create temporary folder", true) err = os.Mkdir(path.Join(rulesPath, "whitelists"), 0755) handleError(err, "unable to create temporary subfolder", true) @@ -113,7 +112,7 @@ func writeRulesFiles(content fs.FS) string { // read embedded content f, err := content.Open(path.Join("data", rulesFile)) handleError(err, "unable to read embedded rule", true) - ruleData, err := ioutil.ReadAll(f) + ruleData, err := io.ReadAll(f) // write to temporary file err = os.WriteFile(path.Join(rulesPath, rulesFile), ruleData, 0640) @@ -141,12 +140,12 @@ func updateRules() { err := resp.Body.Close() handleError(err, "unable to close response body", false) }() - data, err := ioutil.ReadAll(resp.Body) + data, err := io.ReadAll(resp.Body) handleError(err, "unable to read response body", false) return data } writeFile := func(dst string, data []byte) { - err := ioutil.WriteFile(dst, data, 0640) + err := os.WriteFile(dst, data, 0640) handleError(err, "unable to write downloaded file", true) } @@ -276,7 +275,7 @@ func loadRulesFile(fileName string) (*yara.Rules, error) { } // read file content - data, err := ioutil.ReadFile(ruleName) + data, err := os.ReadFile(ruleName) if err != nil { return nil, fmt.Errorf("unable to read rules file: %v", err) } -- cgit v1.3