mirror of
https://github.com/Luzifer/yaml-vault.git
synced 2024-12-21 04:21:16 +00:00
23 lines
524 B
Go
23 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")
|
|
}
|