Support parsing json config with hcl v2

Signed-off-by: Patrick Van Stee <patrick@vanstee.me>
pull/280/head
Patrick Van Stee 5 years ago
parent eadf5eddbc
commit 340686a383
No known key found for this signature in database
GPG Key ID: BF979CB547EC707B

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/hcl/v2/ext/userfunc"
"github.com/hashicorp/hcl/v2/hclsimple"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/hcl/v2/json"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"
"github.com/zclconf/go-cty/cty/function/stdlib"
@ -73,8 +74,16 @@ type staticConfig struct {
}
func ParseHCL(dt []byte, fn string) (*Config, error) {
var file *hcl.File
var diags hcl.Diagnostics
// Decode user defined functions.
file, diags := hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1})
fnl := strings.ToLower(fn)
if strings.HasSuffix(fnl, ".json") {
file, diags = json.Parse(dt, fn)
} else {
file, diags = hclsyntax.ParseConfig(dt, fn, hcl.Pos{Line: 1, Column: 1})
}
if diags.HasErrors() {
return nil, diags
}

Loading…
Cancel
Save