README: include a short Go example using the hclsimple API

This commit is contained in:
Martin Atkins 2019-10-01 16:20:52 -07:00
parent 34955ebf80
commit 46f91bd139

View File

@ -23,6 +23,31 @@ names and nested block types are expected, and HCL parses the configuration
file, verifies that it conforms to the expected structure, and returns file, verifies that it conforms to the expected structure, and returns
high-level objects that the application can use for further processing. high-level objects that the application can use for further processing.
```go
package main
import (
"log"
"github.com/hashicorp/hcl/v2/hclsimple"
)
type Config struct {
LogLevel string `hcl:"log_level"`
}
func main() {
var config Config
err := hclsimple.DecodeFile("config.hcl", nil, &config)
if err != nil {
log.Fatalf("Failed to load configuration: %s", err)
}
log.Printf("Configuration is %#v", config)
}
```
A lower-level API is available for applications that need more control over
the parsing, decoding, and evaluation of configuration.
## Why? ## Why?
Newcomers to HCL often ask: why not JSON, YAML, etc? Newcomers to HCL often ask: why not JSON, YAML, etc?