doc error: gohcl.EvalContext not implemented, but mentioned in the doc
- Dominant language
- Go
- Stars
- 5.8k
- Forks
- 657
- Avg merge
- 20h 36m
- Merged PRs (30d)
- 6
Description
Hi,
I stumbled over this promising `gohcl.EvalContext()` description. It would be really useful for `gohcl` but, not implemented (yet?) and the user of the high-level `gohcl` must go into the low level rabbit hole of `cty`.
Please correct the documentation or ... wait, much better, please implement `gohcl.EvalContext()` as described below ;)
[go_decoding_gohcl.html](https://hcl.readthedocs.io/en/latest/go_decoding_gohcl.html)
### Variables and Functions
By default, arguments given in the configuration may use only literal values and the built in expression language operators, such as arithmetic.
The second argument to `gohcl.DecodeBody`, shown as `nil` in the previous example, allows the calling application to additionally offer variables and functions for use in expressions. Its value is a pointer to an `hcl.EvalContext`, which will be covered in more detail in the later section [Expression Evaluation](https://hcl.readthedocs.io/en/latest/go_expression_eval.html#go-expression-eval). For now, a simple example of making the id of the current process available as a single variable called pid:
```
type Context struct {
Pid string
}
ctx := gohcl.EvalContext(&Context{
Pid: os.Getpid()
})
var c Config
moreDiags := gohcl.DecodeBody(f.Body, ctx, &c)
diags = append(diags, moreDiags...)
```
**gohcl.EvalContext** constructs an expression evaluation context from a Go struct value, making the fields available as variables and the methods available as functions, after transforming the field and method names such that each word (starting with an uppercase letter) is all lowercase and separated by underscores.
`name = "example-program (${pid})"`
btw, thanks for HCL!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.