【发布时间】:2020-08-28 18:34:46
【问题描述】:
全部,
我确信这很容易,但有点挣扎 - 尝试编写一个 yaml 文件,该文件将在使用 gopkg.in/yaml.v3 的 Go 程序中使用。我需要定义服务器列表及其相关元数据。在 JSON 中这是一个相当简单的过程,它在 yaml 文件中是如何处理的。
Go 代码结构如下。
type Config struct {
Servers struct {
Servers struct {
ServerType string `yaml:"serverType"`
ServerPort int `yaml:"serverPort"`
Auth struct {
AuthType string `yaml:"auth"`
TLSKey string `yaml:"tls"`
} `yaml:"auth"`
}`yaml:"server"`
} `yaml:"Servers"`
}
yaml文件长这样
Servers:
server:
serverType: production
serverPort: 80
auth:
auth: no
tls:
server:
serverType: test
serverPort: 8080
auth:
auth: no
tls:
我确定我遗漏了一些相当明显的东西 - 有什么智慧的话可以帮助我前进吗?
谢谢
【问题讨论】: