From fe0a161fb8e31fafe5ebb55be4756eaed1a35e5e Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Sun, 19 Jan 2025 21:14:08 -0800 Subject: [PATCH] [chore] initialize regexps with MustCompile, simplify init --- internal/naming/triming.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/naming/triming.go b/internal/naming/triming.go index 4b2dde37e4..68149e530a 100644 --- a/internal/naming/triming.go +++ b/internal/naming/triming.go @@ -22,12 +22,10 @@ import ( "regexp" ) -var regexpEndReplace, regexpBeginReplace *regexp.Regexp - -func init() { - regexpEndReplace, _ = regexp.Compile("[^A-Za-z0-9]+$") - regexpBeginReplace, _ = regexp.Compile("^[^A-Za-z0-9]+") -} +var ( + regexpEndReplace = regexp.MustCompile("[^A-Za-z0-9]+$") + regexpBeginReplace = regexp.MustCompile("^[^A-Za-z0-9]+") +) // Truncate will shorten the length of the instance name so that it contains at most max chars when combined with the fixed part // If the fixed part is already bigger than the max, this function is noop.