-
Notifications
You must be signed in to change notification settings - Fork 0
/
matcher.go
40 lines (34 loc) · 916 Bytes
/
matcher.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
package internal
import (
"regexp"
"strings"
)
// Debug regex with https://regex101.com/
var (
regexpFuncLine = regexp.MustCompile(`^func\s[a-zA-Z0-9]+\(([^)]*)\)\s+[a-zA-Z0-9]*[^{]*{`)
regexpParseDebugLineParseVarName = regexp.MustCompile(`erro\.Errorf\(|erro\.New\(|erro\.Wrap\(`)
)
func MatchFunc(line string) bool {
return regexpFuncLine.Match([]byte(line))
}
func findArgNames(line string) []string {
reMatches := regexpParseDebugLineParseVarName.FindIndex([]byte(line))
matches := len(reMatches)
if matches > 0 {
args := extractArgs(line[matches:])
return args
} else {
return nil
}
}
func MatchVarName(line string) *string {
reMatches := regexpParseDebugLineParseVarName.FindIndex([]byte(line))
matches := len(reMatches)
if matches > 0 {
args := extractArgs(line[matches:])
errorName := strings.TrimSpace(args[1])
return &errorName
} else {
return nil
}
}