-
Notifications
You must be signed in to change notification settings - Fork 80
/
engine.go
44 lines (39 loc) · 956 Bytes
/
engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package engine
import (
"context"
"log"
"regexp"
"sync"
"github.com/insidersec/insider/report"
)
type Engine struct {
logger *log.Logger
exclude []*regexp.Regexp
ruleBuilder RuleBuilder
jobs int
}
func New(ruleBuilder RuleBuilder, exclude []*regexp.Regexp, jobs int, logger *log.Logger) *Engine {
return &Engine{
logger: logger,
exclude: exclude,
ruleBuilder: ruleBuilder,
jobs: jobs,
}
}
func (e *Engine) Scan(ctx context.Context, dir string) (report.Result, error) {
e.logger.Printf("Analysing files on directory %s\n", dir)
scanner := &scanner{
logger: e.logger,
mutext: new(sync.Mutex),
wg: new(sync.WaitGroup),
ch: make(chan bool, e.jobs),
errors: make([]error, 0),
ctx: ctx,
result: new(Result),
ruleBuilder: e.ruleBuilder,
ruleSet: NewRuleSet(),
dir: dir,
exclude: e.exclude,
}
return scanner.Process()
}