From 73ceab9418721e791816a15b34f93a7b34c80a49 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 7 Mar 2021 21:32:42 -0500 Subject: [PATCH] Update responses to use slice instead of pointer --- main.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 0b4ba8d..4263dba 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( "time" ) -type callbackFunc func(*yara.MatchRules, error) +type callbackFunc func(yara.MatchRules, error) type Job struct { Data io.ReadCloser @@ -143,9 +143,9 @@ func scanHandler(w http.ResponseWriter, r *http.Request) { job := &Job{ Data: f, - Callback: func(m *yara.MatchRules, err error) { + Callback: func(m yara.MatchRules, err error) { fileLock.Lock() - res.Files[file.Filename] = *m + res.Files[file.Filename] = m fileLock.Unlock() wg.Done() @@ -158,20 +158,18 @@ func scanHandler(w http.ResponseWriter, r *http.Request) { log.WithField("count", fileCount).Debug("Waiting for jobs to finish") - wg.Wait() - log.WithField("matches", res).Debug("Matched rules") json.NewEncoder(w).Encode(res) default: job := &Job{ Data: r.Body, - Callback: func(m *yara.MatchRules, err error) { + Callback: func(m yara.MatchRules, err error) { log.WithField("match", m).Debug("Matched rules") if err != nil { json.NewEncoder(w).Encode(response{Success: false, Error: err}) } else { - json.NewEncoder(w).Encode(response{Success: true, MatchedRules: *m}) + json.NewEncoder(w).Encode(response{Success: true, MatchedRules: m}) } }, } @@ -252,7 +250,7 @@ func worker(rules *yara.Rules) { } func processJob(s *yara.Scanner, job *Job) { - var m yara.MatchRules + m := make(yara.MatchRules, 0) defer job.Data.Close() @@ -270,5 +268,5 @@ func processJob(s *yara.Scanner, job *Job) { return } - job.Callback(&m, nil) + job.Callback(m, nil) }