diff --git a/influx/templates.go b/influx/templates.go index 24f5338ba..3cdded215 100644 --- a/influx/templates.go +++ b/influx/templates.go @@ -2,21 +2,21 @@ package influx import "strings" -// TempValue is a value use to replace a template in an InfluxQL query -type TempValue struct { +// TemplateValue is a value use to replace a template in an InfluxQL query +type TemplateValue struct { Value string `json:"value"` Type string `json:"type"` } -// TempVar is a named variable within an InfluxQL query to be replaced with Values -type TempVar struct { - Var string `json:"tempVar"` - Values []TempValue `json:"values"` +// TemplateVar is a named variable within an InfluxQL query to be replaced with Values +type TemplateVar struct { + Var string `json:"tempVar"` + Values []TemplateValue `json:"values"` } // String converts the template variable into a correct InfluxQL string based // on its type -func (t TempVar) String() string { +func (t TemplateVar) String() string { if len(t.Values) == 0 { return "" } @@ -32,13 +32,13 @@ func (t TempVar) String() string { } } -// TempVars are template variables to replace within an InfluxQL query -type TempVars struct { - Vars []TempVar `json:"tempVars"` +// TemplateVars are template variables to replace within an InfluxQL query +type TemplateVars struct { + Vars []TemplateVar `json:"tempVars"` } // TemplateReplace replaces templates with values within the query string -func TemplateReplace(query string, templates TempVars) string { +func TemplateReplace(query string, templates TemplateVars) string { replacements := []string{} for _, v := range templates.Vars { newVal := v.String() diff --git a/influx/templates_test.go b/influx/templates_test.go index ba0ba2640..794b8522e 100644 --- a/influx/templates_test.go +++ b/influx/templates_test.go @@ -8,17 +8,17 @@ func TestTemplateReplace(t *testing.T) { tests := []struct { name string query string - vars TempVars + vars TemplateVars want string }{ { name: "select with parameters", query: "$METHOD field1, $field FROM $measurement WHERE temperature > $temperature", - vars: TempVars{ - Vars: []TempVar{ + vars: TemplateVars{ + Vars: []TemplateVar{ { Var: "$temperature", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "csv", Value: "10", @@ -27,7 +27,7 @@ func TestTemplateReplace(t *testing.T) { }, { Var: "$field", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "fieldKey", Value: "field2", @@ -36,7 +36,7 @@ func TestTemplateReplace(t *testing.T) { }, { Var: "$METHOD", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "csv", Value: "SELECT", @@ -45,7 +45,7 @@ func TestTemplateReplace(t *testing.T) { }, { Var: "$measurement", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "csv", Value: `"cpu"`, @@ -59,11 +59,11 @@ func TestTemplateReplace(t *testing.T) { { name: "select with parameters and aggregates", query: `SELECT mean($field) FROM "cpu" WHERE $tag = $value GROUP BY $tag`, - vars: TempVars{ - Vars: []TempVar{ + vars: TemplateVars{ + Vars: []TemplateVar{ { Var: "$value", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "tagValue", Value: "howdy.com", @@ -72,7 +72,7 @@ func TestTemplateReplace(t *testing.T) { }, { Var: "$tag", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "tagKey", Value: "host", @@ -81,7 +81,7 @@ func TestTemplateReplace(t *testing.T) { }, { Var: "$field", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "fieldKey", Value: "field", @@ -100,8 +100,8 @@ func TestTemplateReplace(t *testing.T) { { name: "var without a value", query: `SELECT $field FROM "cpu"`, - vars: TempVars{ - Vars: []TempVar{ + vars: TemplateVars{ + Vars: []TemplateVar{ { Var: "$field", }, @@ -112,11 +112,11 @@ func TestTemplateReplace(t *testing.T) { { name: "var with unknown type", query: `SELECT $field FROM "cpu"`, - vars: TempVars{ - Vars: []TempVar{ + vars: TemplateVars{ + Vars: []TemplateVar{ { Var: "$field", - Values: []TempValue{ + Values: []TemplateValue{ { Type: "who knows?", Value: "field",