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

gohcl: skip encoding additional nil fields #526

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jedevc
Copy link

@jedevc jedevc commented Apr 13, 2022

This patch skips encoding nil slices, maps and interfaces, in addition to the already skipped nil pointers.

The scenario I've run into this in is something like the following:

type X struct {
	A *string  `hcl:"a"`
	B []string `hcl:"b"`
}

...

f := hclwrite.NewEmptyFile()
block := gohcl.EncodeAsBlock(X{}, "test")
f.Body().AppendBlock(block)
fmt.Println(string(f.Bytes()))

Without the patch I get:

test {
  b = null
}

While with the patch, I get:

test {
}

Hopefully this small change is something worth incorporating!

@hashicorp-cla
Copy link

hashicorp-cla commented Apr 13, 2022

CLA assistant check
All committers have signed the CLA.

This patch skips encoding nil slices, maps and interfaces, in addition
to the already skipped nil pointers.

Signed-off-by: Justin Chadwell <me@jedevc.com>
@jedevc
Copy link
Author

jedevc commented Apr 27, 2022

Is there anything currently blocking this?

@yuri-tceretian
Copy link

yuri-tceretian commented Aug 30, 2023

I think the change does a good thing. Any chance it can be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants