From bb12a1bc9948cd0172df526b4b393a016abc4779 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Fri, 19 Oct 2018 19:09:21 +0200 Subject: [PATCH] pkg/tsdb/graphite/graphite.go: Fix regular expression does not contain any meta characters. I found this article benchmarking Replace vs Regexp, https://medium.com/codezillas/golang-replace-vs-regexp-de4e48482f53 See, $ gometalinter --vendor --deadline 10m --disable-all --enable=megacheck ./... pkg/tsdb/graphite/graphite.go:167:28:warning: regular expression does not contain any meta characters (SA6004) (megacheck) pkg/tsdb/graphite/graphite.go:172:28:warning: regular expression does not contain any meta characters (SA6004) (megacheck) --- pkg/tsdb/graphite/graphite.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/tsdb/graphite/graphite.go b/pkg/tsdb/graphite/graphite.go index 2960ba0edc4..ff0ed8d0620 100644 --- a/pkg/tsdb/graphite/graphite.go +++ b/pkg/tsdb/graphite/graphite.go @@ -164,14 +164,12 @@ func formatTimeRange(input string) string { func fixIntervalFormat(target string) string { rMinute := regexp.MustCompile(`'(\d+)m'`) - rMin := regexp.MustCompile("m") target = rMinute.ReplaceAllStringFunc(target, func(m string) string { - return rMin.ReplaceAllString(m, "min") + return strings.Replace(m, "m", "min", -1) }) rMonth := regexp.MustCompile(`'(\d+)M'`) - rMon := regexp.MustCompile("M") target = rMonth.ReplaceAllStringFunc(target, func(M string) string { - return rMon.ReplaceAllString(M, "mon") + return strings.Replace(M, "M", "mon", -1) }) return target }