chronograf/influx/templates.go

27 lines
579 B
Go
Raw Normal View History

2017-04-19 16:03:53 +00:00
package influx
import (
"strings"
2017-04-19 16:03:53 +00:00
"github.com/influxdata/chronograf"
)
2017-04-19 16:03:53 +00:00
// TemplateReplace replaces templates with values within the query string
func TemplateReplace(query string, templates chronograf.TemplateVars) string {
2017-04-19 16:03:53 +00:00
replacements := []string{}
for _, v := range templates {
if evar, ok := v.(chronograf.ExecutableVar); ok {
evar.Exec(query)
}
2017-04-19 16:03:53 +00:00
newVal := v.String()
if newVal != "" {
replacements = append(replacements, v.Name(), newVal)
2017-04-19 16:03:53 +00:00
}
}
replacer := strings.NewReplacer(replacements...)
replaced := replacer.Replace(query)
return replaced
}