node-api/detector/main.go
Adam Štrauch a213fac34a
Some checks failed
continuous-integration/drone/push Build is failing
Flags support
2022-02-03 01:31:47 +01:00

38 lines
764 B
Go

package detector
import (
"fmt"
"regexp"
)
// Flags is list of strings describing problems found among the processes
type Flags []string
// Check goes over patterns and tries to flag given list of processes with flags.
func Check(processes []string) (Flags, error) {
flags := Flags{}
tmpFlags := make(map[string]bool)
for _, process := range processes {
for flag, patternSet := range patterns {
for _, pattern := range patternSet {
matched, err := regexp.MatchString(".*"+pattern+".*", process)
if err != nil {
return flags, err
}
if matched {
tmpFlags[flag] = true
break
}
fmt.Println(process, pattern, flag)
}
}
}
for flag, _ := range tmpFlags {
flags = append(flags, flag)
}
return flags, nil
}