diff options
| author | Martin Atkins <mart@degeneration.co.uk> | 2019-10-01 16:20:52 -0700 |
|---|---|---|
| committer | Martin Atkins <mart@degeneration.co.uk> | 2019-10-01 16:20:52 -0700 |
| commit | 46f91bd1399e16fa706d43c86914d95824c7fdfb (patch) | |
| tree | 8eb3698838e0745f51a58e41a28cc9b48f7a5795 /README.md | |
| parent | 34955ebf808c8ac2b6d0e0fd2368d9f8c5efad5e (diff) | |
README: include a short Go example using the hclsimple API
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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 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? Newcomers to HCL often ask: why not JSON, YAML, etc? |
