Skip to content

Commit b014ebf

Browse files
committed
finder refactoring
1 parent 7d05941 commit b014ebf

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

finder.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
"github.com/dlclark/regexp2"
1313
)
1414

15-
func pathsFinder(files *[]string, patterns []*regexp2.Regexp) *[]string {
15+
// PathsFinder try to match regular expressions in file paths slice
16+
func PathsFinder(files *[]string, patterns []*regexp2.Regexp) *[]string {
1617
var matchingFiles []string
1718
for _, expression := range patterns {
1819
for _, f := range *files {
@@ -25,7 +26,8 @@ func pathsFinder(files *[]string, patterns []*regexp2.Regexp) *[]string {
2526
return &matchingFiles
2627
}
2728

28-
func findInFiles(files *[]string, patterns []string, checksum []string) *[]string {
29+
// FindInFiles check for pattern or checksum match in files slice
30+
func FindInFiles(files *[]string, patterns []string, checksum []string) *[]string {
2931
var matchingFiles []string
3032
for _, f := range *files {
3133
b, err := ioutil.ReadFile(f)

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func main() {
129129
re := regexp2.MustCompile(pattern, regexp2.IgnoreCase)
130130
pathRegexPatterns = append(pathRegexPatterns, re)
131131
}
132-
matchPattern = pathsFinder(files, pathRegexPatterns)
132+
matchPattern = PathsFinder(files, pathRegexPatterns)
133133
if !config.Options.ContentMatchDependsOnPathMatch {
134134
for _, file := range *matchPattern {
135135
LogMessage(LOG_INFO, "[ALERT]", "File match on", file)
@@ -144,9 +144,9 @@ func main() {
144144
if len(config.Input.Content.Grep) > 0 || len(config.Input.Content.Checksum) > 0 {
145145
LogMessage(LOG_INFO, "[INFO]", "Checking for content and checksum matchs in", basePath)
146146
if config.Options.ContentMatchDependsOnPathMatch {
147-
matchContent = findInFiles(matchPattern, config.Input.Content.Grep, config.Input.Content.Checksum)
147+
matchContent = FindInFiles(matchPattern, config.Input.Content.Grep, config.Input.Content.Checksum)
148148
} else {
149-
matchContent = findInFiles(files, config.Input.Content.Grep, config.Input.Content.Checksum)
149+
matchContent = FindInFiles(files, config.Input.Content.Grep, config.Input.Content.Checksum)
150150
}
151151
}
152152

0 commit comments

Comments
 (0)