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⚠️ regular expression does not contain any meta characters (SA6004) (megacheck)
pkg/tsdb/graphite/graphite.go:172:28⚠️ regular expression does not contain any meta characters (SA6004) (megacheck)
This commit is contained in:
Mario Trangoni 2018-10-19 19:09:21 +02:00
parent 3466969a7c
commit bb12a1bc99

View File

@ -164,14 +164,12 @@ func formatTimeRange(input string) string {
func fixIntervalFormat(target string) string { func fixIntervalFormat(target string) string {
rMinute := regexp.MustCompile(`'(\d+)m'`) rMinute := regexp.MustCompile(`'(\d+)m'`)
rMin := regexp.MustCompile("m")
target = rMinute.ReplaceAllStringFunc(target, func(m string) string { 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'`) rMonth := regexp.MustCompile(`'(\d+)M'`)
rMon := regexp.MustCompile("M")
target = rMonth.ReplaceAllStringFunc(target, func(M string) string { target = rMonth.ReplaceAllStringFunc(target, func(M string) string {
return rMon.ReplaceAllString(M, "mon") return strings.Replace(M, "M", "mon", -1)
}) })
return target return target
} }