Output error from encoding
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
0356da8fa2
commit
37851c8ee2
22
main.go
22
main.go
|
@ -109,8 +109,6 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
contentType = contentType[0:idx]
|
contentType = contentType[0:idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
|
|
||||||
switch contentType {
|
switch contentType {
|
||||||
case "multipart/form-data":
|
case "multipart/form-data":
|
||||||
if r.MultipartForm == nil {
|
if r.MultipartForm == nil {
|
||||||
|
@ -128,6 +126,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
fileLock := &sync.Mutex{}
|
fileLock := &sync.Mutex{}
|
||||||
|
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
for _, files := range r.MultipartForm.File {
|
for _, files := range r.MultipartForm.File {
|
||||||
// Append files
|
// Append files
|
||||||
for _, file := range 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("count", fileCount).Debug("Waiting for jobs to finish")
|
||||||
|
|
||||||
log.WithField("matches", res).Debug("Matched rules")
|
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:
|
default:
|
||||||
job := &Job{
|
job := &Job{
|
||||||
Data: r.Body,
|
Data: r.Body,
|
||||||
Callback: func(m yara.MatchRules, err error) {
|
Callback: func(m yara.MatchRules, err error) {
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
log.WithField("match", m).Debug("Matched rules")
|
log.WithField("match", m).Debug("Matched rules")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
json.NewEncoder(w).Encode(response{Success: false, Error: err})
|
err = json.NewEncoder(w).Encode(response{Success: false, Error: err})
|
||||||
} else {
|
} 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")
|
log.WithField("contentType", contentType).Debug("Scanning contents of body")
|
||||||
|
|
||||||
jobChan <- job
|
jobChan <- job
|
||||||
|
|
||||||
wg.Wait()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue