Skip to content

Is possible add pretty print to a file? #705

Answered by pelletier
TeoDev1611 asked this question in Questions
Discussion options

You must be logged in to vote

Hi! The best you can probably do right now is to decode into an interface{}, then encode that value back: https://go.dev/play/p/KlPdwxijdt_I

This will emit a "standard" (as far as go-toml is concerned) representation of the data. Because TOML has multiple ways to represent the same data structure, the encoder has to make some default choices, which may not match the style of the input document – for example it does not use inline tables by default.

Today, the only way to have a bit more control over the output is to know in advance as much of the structure as possible. Instead of decoding into an interface{}, decode into a struct that provides struct field tags to tweak the output style.

T…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TeoDev1611
Comment options

Answer selected by TeoDev1611
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants