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

Add Encoder option to disable printing of super-table header #957

Open
katexochen opened this issue Jul 15, 2024 · 1 comment
Open

Add Encoder option to disable printing of super-table header #957

katexochen opened this issue Jul 15, 2024 · 1 comment
Labels
feature Issue asking for a new feature in go-toml.

Comments

@katexochen
Copy link

The following example

type a struct{ B b }
type b struct{ C c }
type c struct{ D d }
type d struct{ S string }

func main() {
	var test a
	test.B.C.D.S = "foo"
	out, err := toml.Marshal(test)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(out))
}

will output the following marshaled toml:

[B]
[B.C]
[B.C.D]
S = 'foo'

Citing the TOML spec

# [x] you
# [x.y] don't
# [x.y.z] need these
[x.y.z.w] # for this to work

So it would be nice if there would be a way to omit the empty super-table headers.

This is especially useful in case your last element in the path (D/w) is known to be unique, and you want to append a toml snippet to an existing toml file. If you marshal the snippet and it contains the empty super-table headers, you might redefine the super-table if it is already present in the file your appending to.

@pelletier
Copy link
Owner

That would indeed be nice! Thank you for filing an issue!

@pelletier pelletier added the feature Issue asking for a new feature in go-toml. label Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issue asking for a new feature in go-toml.
Projects
None yet
Development

No branches or pull requests

2 participants