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
merged 1 commit into from Feb 17, 2018

Conversation

Projects
None yet
2 participants
@nicholasjackson
Copy link
Contributor

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 jackson.nic@gmail.com

Added struct tag optional for gohcl
Signed-off-by: nicholasjackson <jackson.nic@gmail.com>
@apparentlymart

This comment has been minimized.

Copy link
Member

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 ./...
?   	github.com/hashicorp/hcl2/cmd/hcldec	[no test files]
?   	github.com/hashicorp/hcl2/cmd/hclfmt	[no test files]
ok  	github.com/hashicorp/hcl2/ext/dynblock	0.007s
ok  	github.com/hashicorp/hcl2/ext/include	0.012s
ok  	github.com/hashicorp/hcl2/ext/transform	0.006s
ok  	github.com/hashicorp/hcl2/ext/userfunc	0.034s
ok  	github.com/hashicorp/hcl2/gohcl	0.010s
ok  	github.com/hashicorp/hcl2/hcl	0.003s
ok  	github.com/hashicorp/hcl2/hcl/hclsyntax	0.031s
?   	github.com/hashicorp/hcl2/hcl/hclsyntax/fuzz/config	[no test files]
?   	github.com/hashicorp/hcl2/hcl/hclsyntax/fuzz/expr	[no test files]
?   	github.com/hashicorp/hcl2/hcl/hclsyntax/fuzz/template	[no test files]
?   	github.com/hashicorp/hcl2/hcl/hclsyntax/fuzz/traversal	[no test files]
ok  	github.com/hashicorp/hcl2/hcl/integrationtest	0.003s
ok  	github.com/hashicorp/hcl2/hcl/json	0.004s
?   	github.com/hashicorp/hcl2/hcl/json/fuzz/config	[no test files]
ok  	github.com/hashicorp/hcl2/hcldec	0.003s
?   	github.com/hashicorp/hcl2/hcled	[no test files]
?   	github.com/hashicorp/hcl2/hclparse	[no test files]
ok  	github.com/hashicorp/hcl2/hcltest	0.002s
ok  	github.com/hashicorp/hcl2/hclwrite	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.