diff --git a/hcledit.go b/hcledit.go index c6ab425..216075b 100644 --- a/hcledit.go +++ b/hcledit.go @@ -49,7 +49,7 @@ func (h *HCLEditor) Create(queryStr string, value interface{}, opts ...Option) e defer h.reload() opt := &option{ - querySeparator: ".", + querySeparator: '.', } for _, optFunc := range opts { optFunc(opt) @@ -81,7 +81,7 @@ func (h *HCLEditor) Read(queryStr string, opts ...Option) (map[string]interface{ defer h.reload() opt := &option{ - querySeparator: ".", + querySeparator: '.', } for _, optFunc := range opts { optFunc(opt) @@ -127,7 +127,7 @@ func (h *HCLEditor) Update(queryStr string, value interface{}, opts ...Option) e defer h.reload() opt := &option{ - querySeparator: ".", + querySeparator: '.', } for _, optFunc := range opts { optFunc(opt) @@ -170,7 +170,7 @@ func (h *HCLEditor) Delete(queryStr string, opts ...Option) error { defer h.reload() opt := &option{ - querySeparator: ".", + querySeparator: '.', } for _, optFunc := range opts { optFunc(opt) diff --git a/hcledit_test.go b/hcledit_test.go index 1f8588e..000969c 100644 --- a/hcledit_test.go +++ b/hcledit_test.go @@ -127,7 +127,7 @@ object = { } `, query: "object|attribute3.value", - opts: []hcledit.Option{hcledit.WithQuerySeparator("|")}, + opts: []hcledit.Option{hcledit.WithQuerySeparator('|')}, value: "D", want: ` object = { diff --git a/internal/query/query.go b/internal/query/query.go index b1736b8..c5a5ec4 100644 --- a/internal/query/query.go +++ b/internal/query/query.go @@ -30,9 +30,9 @@ func (c *queryWildcard) Key() string { return "*" } -func Build(src, querySeparator string) ([]Query, error) { +func Build(src string, querySeparator rune) ([]Query, error) { var queries []Query - for _, q := range strings.Split(src, querySeparator) { + for _, q := range strings.Split(src, string([]rune{querySeparator})) { if q == "*" { queries = append(queries, &queryWildcard{}) } else { diff --git a/option.go b/option.go index 6af2b3b..7060533 100644 --- a/option.go +++ b/option.go @@ -5,7 +5,7 @@ type option struct { afterKey string beforeNewline bool readFallbackToRawString bool - querySeparator string + querySeparator rune } // Option configures specific behavior for specific HCLEditor operations. @@ -43,8 +43,8 @@ func WithReadFallbackToRawString() Option { } // This sets a separator for queryStr in HCLEditor funcs. The default separator is ".". -func WithQuerySeparator(chr string) Option { +func WithQuerySeparator(r rune) Option { return func(opt *option) { - opt.querySeparator = chr + opt.querySeparator = r } } diff --git a/option_test.go b/option_test.go index b16b1cd..ff377e2 100644 --- a/option_test.go +++ b/option_test.go @@ -246,7 +246,7 @@ object = { } `, exec: func(editor *hcledit.HCLEditor) error { - return editor.Create("object/attribute", "str", hcledit.WithQuerySeparator("/")) + return editor.Create("object/attribute", "str", hcledit.WithQuerySeparator('/')) }, want: ` object = {