Closed fmuyassarov closed 6 months ago
The answer to this question depends largely on what types are involved and the kind of operations you want to make.
go-toml has support for commented struct fields (example).
You can also use the unstable.AST
to parse the document, keeping comments. However there is no easy way to write it back out at the moment. You should be able to generate your own struct types dynamically to achieve this. Check out https://github.com/pelletier/go-toml/issues/822 about this topic – pull request to add encoder methods to the unstable.AST would be welcomed!
Closing this, feel free to open a discussion if there is more to discuss about this subject!
Hi. Does go-toml v2 support keeping the commented out lines of a TOML file when unmarshaling and marshaling? I'm manipulating a TOML based configuration file and eventually, commented out lines are getting clean up. It would be nice to have an option to keep them as it is.
Example