summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMathieu Deous2023-01-05 21:58:12 +0100
committerGitHub2023-01-05 21:58:12 +0100
commit55b85b9cac07a1c95195e00d038e893112f9c879 (patch)
tree38fd4ea05f4f4a2aa9ae7539511f7974e0d569cc /main.go
parent15e5ed592b05a1ddbc433a8ee2596cd9d23eb464 (diff)
Update deprecated funcs and gh actions (#123)
* migrate deprecated functions * update github actions
Diffstat (limited to '')
-rw-r--r--main.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/main.go b/main.go
index d5f8d69..de64b90 100644
--- a/main.go
+++ b/main.go
@@ -6,7 +6,6 @@ import (
6 "fmt" 6 "fmt"
7 "io" 7 "io"
8 "io/fs" 8 "io/fs"
9 "io/ioutil"
10 "log" 9 "log"
11 "net/http" 10 "net/http"
12 "os" 11 "os"
@@ -103,7 +102,7 @@ func handleError(err error, desc string, isFatal bool) {
103// returns its location. 102// returns its location.
104func writeRulesFiles(content fs.FS) string { 103func writeRulesFiles(content fs.FS) string {
105 // create temporary folder structure 104 // create temporary folder structure
106 rulesPath, err := ioutil.TempDir(os.TempDir(), TempDirPrefix) 105 rulesPath, err := os.MkdirTemp(os.TempDir(), TempDirPrefix)
107 handleError(err, "unable to create temporary folder", true) 106 handleError(err, "unable to create temporary folder", true)
108 err = os.Mkdir(path.Join(rulesPath, "whitelists"), 0755) 107 err = os.Mkdir(path.Join(rulesPath, "whitelists"), 0755)
109 handleError(err, "unable to create temporary subfolder", true) 108 handleError(err, "unable to create temporary subfolder", true)
@@ -113,7 +112,7 @@ func writeRulesFiles(content fs.FS) string {
113 // read embedded content 112 // read embedded content
114 f, err := content.Open(path.Join("data", rulesFile)) 113 f, err := content.Open(path.Join("data", rulesFile))
115 handleError(err, "unable to read embedded rule", true) 114 handleError(err, "unable to read embedded rule", true)
116 ruleData, err := ioutil.ReadAll(f) 115 ruleData, err := io.ReadAll(f)
117 116
118 // write to temporary file 117 // write to temporary file
119 err = os.WriteFile(path.Join(rulesPath, rulesFile), ruleData, 0640) 118 err = os.WriteFile(path.Join(rulesPath, rulesFile), ruleData, 0640)
@@ -141,12 +140,12 @@ func updateRules() {
141 err := resp.Body.Close() 140 err := resp.Body.Close()
142 handleError(err, "unable to close response body", false) 141 handleError(err, "unable to close response body", false)
143 }() 142 }()
144 data, err := ioutil.ReadAll(resp.Body) 143 data, err := io.ReadAll(resp.Body)
145 handleError(err, "unable to read response body", false) 144 handleError(err, "unable to read response body", false)
146 return data 145 return data
147 } 146 }
148 writeFile := func(dst string, data []byte) { 147 writeFile := func(dst string, data []byte) {
149 err := ioutil.WriteFile(dst, data, 0640) 148 err := os.WriteFile(dst, data, 0640)
150 handleError(err, "unable to write downloaded file", true) 149 handleError(err, "unable to write downloaded file", true)
151 } 150 }
152 151
@@ -276,7 +275,7 @@ func loadRulesFile(fileName string) (*yara.Rules, error) {
276 } 275 }
277 276
278 // read file content 277 // read file content
279 data, err := ioutil.ReadFile(ruleName) 278 data, err := os.ReadFile(ruleName)
280 if err != nil { 279 if err != nil {
281 return nil, fmt.Errorf("unable to read rules file: %v", err) 280 return nil, fmt.Errorf("unable to read rules file: %v", err)
282 } 281 }