-
Notifications
You must be signed in to change notification settings - Fork 589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc error: gohcl.EvalContext not implemented, but mentioned in the doc #565
Comments
Hey @gaissmai, I noticed this problem and working on it. |
Hey @incubator4, thanks for implementing this. I see just the variable part und no functions/methods. Am I missing something? |
Actually you're right ,I'm working on it,so I just finished variable part before. Cause of without demo in doc,I'm still considering about how to implement function part. In my opinion, the struct contains variable pid with certain value should be render into final string , it should be like name = "example-program a-pid-value" How to implement function part is a problem, or may I understand some mistakes. If you have any idea about that, we can communicate in this issue. |
Hello @incubator4, i think this is only possible with method values |
Well, I've checked code abount function func decodeLiteralSpec(body hcl.Body) (hcldec.Spec, hcl.Diagnostics) {
type content struct {
Value cty.Value `hcl:"value"`
}
var args content
diags := gohcl.DecodeBody(body, specCtx, &args)
if diags.HasErrors() {
return errSpec, diags
}
return &hcldec.LiteralSpec{
Value: args.Value,
}, diags
} This specCtx use a var specFuncs = map[string]function.Function{
"abs": stdlib.AbsoluteFunc,
"coalesce": stdlib.CoalesceFunc,
"concat": stdlib.ConcatFunc,
"hasindex": stdlib.HasIndexFunc,
"int": stdlib.IntFunc,
"jsondecode": stdlib.JSONDecodeFunc,
"jsonencode": stdlib.JSONEncodeFunc,
"length": stdlib.LengthFunc,
"lower": stdlib.LowerFunc,
"max": stdlib.MaxFunc,
"min": stdlib.MinFunc,
"reverse": stdlib.ReverseFunc,
"strlen": stdlib.StrlenFunc,
"substr": stdlib.SubstrFunc,
"upper": stdlib.UpperFunc,
} In my opinion, suppose that |
Hey @incubator4 , sorry for the delay. Maybe I don't understand what you want to show me. Anyway, do you know this blogpost: build your own DSL with go and e.g. the implementation of the |
I've already finished this post. The key info I thought , which was golang function -> I could try to finish function part, it should be implement as same as the variables with reflect. |
Hey @gaissmai . During reading abount In short, this library provides a conversion method from There are two solutions that can be thought of at present,
Do you or any others have idea ? |
Hi,
I stumbled over this promising
gohcl.EvalContext()
description. It would be really useful forgohcl
but, not implemented (yet?) and the user of the high-levelgohcl
must go into the low level rabbit hole ofcty
.Please correct the documentation or ... wait, much better, please implement
gohcl.EvalContext()
as described below ;)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 asnil
in the previous example, allows the calling application to additionally offer variables and functions for use in expressions. Its value is a pointer to anhcl.EvalContext
, which will be covered in more detail in the later section Expression Evaluation. For now, a simple example of making the id of the current process available as a single variable called pid: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!
The text was updated successfully, but these errors were encountered: