summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Atkins <mart@degeneration.co.uk>2019-10-01 16:20:52 -0700
committerMartin Atkins <mart@degeneration.co.uk>2019-10-01 16:20:52 -0700
commit46f91bd1399e16fa706d43c86914d95824c7fdfb (patch)
tree8eb3698838e0745f51a58e41a28cc9b48f7a5795
parent34955ebf808c8ac2b6d0e0fd2368d9f8c5efad5e (diff)
README: include a short Go example using the hclsimple API
-rw-r--r--README.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/README.md b/README.md
index 61f26a8..7b7ac71 100644
--- a/README.md
+++ b/README.md
@@ -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?