Output error from encoding
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Tyler 2021-03-07 21:44:10 -05:00
parent 0356da8fa2
commit 37851c8ee2
1 changed files with 13 additions and 9 deletions

22
main.go
View File

@ -109,8 +109,6 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
contentType = contentType[0:idx]
}
wg := &sync.WaitGroup{}
switch contentType {
case "multipart/form-data":
if r.MultipartForm == nil {
@ -128,6 +126,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
fileLock := &sync.Mutex{}
wg := &sync.WaitGroup{}
for _, files := range r.MultipartForm.File {
// Append files
for _, file := range files {
@ -161,19 +161,25 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
log.WithField("count", fileCount).Debug("Waiting for jobs to finish")
log.WithField("matches", res).Debug("Matched rules")
json.NewEncoder(w).Encode(res)
err := json.NewEncoder(w).Encode(res)
if err != nil {
log.WithError(err).Error("Unable to send response")
}
default:
job := &Job{
Data: r.Body,
Callback: func(m yara.MatchRules, err error) {
wg.Add(1)
log.WithField("match", m).Debug("Matched rules")
if err != nil {
json.NewEncoder(w).Encode(response{Success: false, Error: err})
err = json.NewEncoder(w).Encode(response{Success: false, Error: err})
} else {
json.NewEncoder(w).Encode(response{Success: true, MatchedRules: m})
err = json.NewEncoder(w).Encode(response{Success: true, MatchedRules: m})
}
if err != nil {
log.WithError(err).Error("Unable to send response")
}
},
}
@ -181,8 +187,6 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
log.WithField("contentType", contentType).Debug("Scanning contents of body")
jobChan <- job
wg.Wait()
}
}