http urls monitor.

parse.go 892B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package hcl
  2. import (
  3. "fmt"
  4. "github.com/hashicorp/hcl/hcl/ast"
  5. hclParser "github.com/hashicorp/hcl/hcl/parser"
  6. jsonParser "github.com/hashicorp/hcl/json/parser"
  7. )
  8. // ParseBytes accepts as input byte slice and returns ast tree.
  9. //
  10. // Input can be either JSON or HCL
  11. func ParseBytes(in []byte) (*ast.File, error) {
  12. return parse(in)
  13. }
  14. // ParseString accepts input as a string and returns ast tree.
  15. func ParseString(input string) (*ast.File, error) {
  16. return parse([]byte(input))
  17. }
  18. func parse(in []byte) (*ast.File, error) {
  19. switch lexMode(in) {
  20. case lexModeHcl:
  21. return hclParser.Parse(in)
  22. case lexModeJson:
  23. return jsonParser.Parse(in)
  24. }
  25. return nil, fmt.Errorf("unknown config format")
  26. }
  27. // Parse parses the given input and returns the root object.
  28. //
  29. // The input format can be either HCL or JSON.
  30. func Parse(input string) (*ast.File, error) {
  31. return parse([]byte(input))
  32. }