如何在Golang中解码和编码.toml文件的特定部分?
我有点新手Burntsushi/Toml,想了解以下案件的解决方案。
假设我们有一个示例。toml文件,
[foo]
fighter = "this-is-a-call"
gu = "fish-with-wrong-spelling"
[bar]
beer = "guinness"
snacks = "pickled-eggs"
[more_examples_below]
...
据我正确理解,toml.decodefile(path,struct)
用于读取整个示例。
不过,我不明白我应该如何仅针对[bar]
零件进行解码/编码?
因此,我应该在Golang映射所有config.toml中定义整个结构吗?如果是,那么是否有另一种方法可以这样做,只是为1个特定块定义一个结构?
I'm kinda new to BurntSushi/toml and want to learn what are the solutions for the case below.
Let's say we have this example.toml file
[foo]
fighter = "this-is-a-call"
gu = "fish-with-wrong-spelling"
[bar]
beer = "guinness"
snacks = "pickled-eggs"
[more_examples_below]
...
As I understand correctly, toml.DecodeFile(path, struct)
is used for reading the whole example.toml into golang code.
Still, I don't understand how should I do decoding/encoding only for the [bar]
part?
Thus, should I define the whole struct in golang mapping all config.toml? If yes, then is there another way no to do so and just define a struct for 1 specific block?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要编辑现有.TOML文件的特定部分,则VIPER可以成为此工作中的有用替代方法。一些关于如何实现的想法草案
If you need to edit a specific part of an existing .toml file, viper can be a helpful alternative in this job. Some draft idea of how it can be achieved