open-consul/vendor/github.com/hashicorp/hcl/parse.go
Sean Chittenden 333ff22e9a Manage dependencies via Godep
Embrace the future and use Go 1.6's vendor support via Godep.

Go 1.5 users should `export GO15VENDOREXPERIMENT=1`
2016-02-12 16:50:37 -08:00

24 lines
524 B
Go

package hcl
import (
"fmt"
"github.com/hashicorp/hcl/hcl/ast"
hclParser "github.com/hashicorp/hcl/hcl/parser"
jsonParser "github.com/hashicorp/hcl/json/parser"
)
// Parse parses the given input and returns the root object.
//
// The input format can be either HCL or JSON.
func Parse(input string) (*ast.File, error) {
switch lexMode(input) {
case lexModeHcl:
return hclParser.Parse([]byte(input))
case lexModeJson:
return jsonParser.Parse([]byte(input))
}
return nil, fmt.Errorf("unknown config format")
}