Skip to content

Commit 2b9600c

Browse files
Move Regex and regex compilation
1 parent b3b09d7 commit 2b9600c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

context.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,12 @@ func GetCurrentContainerID() string {
168168
scanner := bufio.NewScanner(reader)
169169
scanner.Split(bufio.ScanLines)
170170

171+
regex := "/docker/([[:alnum:]]{64})$"
172+
re := regexp.MustCompilePOSIX(regex)
173+
171174
for scanner.Scan() {
172175
_, lines, err := bufio.ScanLines([]byte(scanner.Text()), true)
173176
if err == nil {
174-
re := regexp.MustCompilePOSIX("/docker/([[:alnum:]]{64})$")
175177
if re.MatchString(string(lines)) {
176178
submatches := re.FindStringSubmatch(string(lines))
177179
containerID := submatches[1]

0 commit comments

Comments
 (0)