Use waitgroup to stall handler?
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
73ceab9418
commit
0356da8fa2
10
main.go
10
main.go
@ -109,14 +109,14 @@ 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 {
|
||||
r.ParseMultipartForm(32 << 20)
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
log.WithField("contentType", contentType).Debug("Adding files from multipart form as jobs")
|
||||
|
||||
fileCount := 0
|
||||
@ -156,6 +156,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
log.WithField("count", fileCount).Debug("Waiting for jobs to finish")
|
||||
|
||||
log.WithField("matches", res).Debug("Matched rules")
|
||||
@ -164,6 +166,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
|
||||
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 {
|
||||
@ -177,6 +181,8 @@ func scanHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.WithField("contentType", contentType).Debug("Scanning contents of body")
|
||||
|
||||
jobChan <- job
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user