Chore: Enable Go linter gocritic (#26224)
* Chore: Enable gocritic linter Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user