Update responses to use slice instead of pointer
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a84d3dc9fc
commit
73ceab9418
16
main.go
16
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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue