Chore: Enable Go linter gocritic (#26224)

* Chore: Enable gocritic linter

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-07-16 14:39:01 +02:00
committed by GitHub
parent 317c7b269c
commit d4e4cb4c71
43 changed files with 184 additions and 171 deletions
+3 -3
View File
@@ -11,6 +11,8 @@ import (
"github.com/grafana/grafana/pkg/services/dashboards"
)
var varRegex = regexp.MustCompile(`(\$\{.+\})`)
type ImportDashboardCommand struct {
Dashboard *simplejson.Json
Path string
@@ -109,7 +111,6 @@ type DashTemplateEvaluator struct {
inputs []ImportDashboardInput
variables map[string]string
result *simplejson.Json
varRegex *regexp.Regexp
}
func (this *DashTemplateEvaluator) findInput(varName string, varType string) *ImportDashboardInput {
@@ -125,7 +126,6 @@ func (this *DashTemplateEvaluator) findInput(varName string, varType string) *Im
func (this *DashTemplateEvaluator) Eval() (*simplejson.Json, error) {
this.result = simplejson.New()
this.variables = make(map[string]string)
this.varRegex, _ = regexp.Compile(`(\$\{.+\})`)
// check that we have all inputs we need
for _, inputDef := range this.template.Get("__inputs").MustArray() {
@@ -149,7 +149,7 @@ func (this *DashTemplateEvaluator) evalValue(source *simplejson.Json) interface{
switch v := sourceValue.(type) {
case string:
interpolated := this.varRegex.ReplaceAllStringFunc(v, func(match string) string {
interpolated := varRegex.ReplaceAllStringFunc(v, func(match string) string {
replacement, exists := this.variables[match]
if exists {
return replacement