Skip to content
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

Added struct tag optional for gohcl #13

merged 1 commit into from Feb 17, 2018


None yet
2 participants
Copy link

commented Feb 17, 2018

Added optional tag for attributes on structs. In the following example, MiddleName is marked as optional and after decoding the field MiddleName on the Person object would be an empty string. For situations where HCL is used for configuration optional rather than a pointer is more explicit. It allows parsing of config with validation without needing to mix value and reference types for simple objects.

struct Person struct {
  FirstName     string `hcl:"first_name"`
  MiddleName string `hcl:"middle_name,optional"`
  Surname       string `hcl:"surname"`
person {
  first_name = "Nic"
  surname    = "Jackson"

I was not sure where to place the docs for this, happy to add docs as an additional commit.

Signed-off-by: nicholasjackson

Added struct tag optional for gohcl
Signed-off-by: nicholasjackson <>

This comment has been minimized.

Copy link

commented Feb 17, 2018

Thanks! This looks great to me.

There is currently no explicit documentation on the mapping rules here since I'd intended to let the implementation "settle" first and then document it, but haven't yet got to that point. I'll write complete docs for this as part of our pass of finalizing this implementation as non-experimental. For now, I'm going to merge this as-is.

This PR also made me realize that we aren't running Travis-CI tests for PRs on this repo since it moved over here into the hashicorp organization. I've now switched that on for future PRs, but for this one I pulled it locally and ran the tests myself:

$ go test ./...
?	[no test files]
?	[no test files]
ok	0.007s
ok	0.012s
ok	0.006s
ok	0.034s
ok	0.010s
ok	0.003s
ok	0.031s
?	[no test files]
?	[no test files]
?	[no test files]
?	[no test files]
ok	0.003s
ok	0.004s
?	[no test files]
ok	0.003s
?	[no test files]
?	[no test files]
ok	0.002s
ok	0.008s

@apparentlymart apparentlymart merged commit 23fc060 into hashicorp:master Feb 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.