1 回答
TA贡献1820条经验 获得超10个赞
粘贴您的 yaml 会产生以下结果:
type AutoGenerated struct {
API struct {
Local struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
} `yaml:"local"`
Develop struct {
Host interface{} `yaml:"host"`
Port interface{} `yaml:"port"`
} `yaml:"develop"`
Production struct {
Host interface{} `yaml:"host"`
Port interface{} `yaml:"port"`
} `yaml:"production"`
} `yaml:"api"`
RestAPI struct {
Local struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
} `yaml:"local"`
Develop struct {
Host interface{} `yaml:"host"`
Port interface{} `yaml:"port"`
} `yaml:"develop"`
Production struct {
Host interface{} `yaml:"host"`
Port interface{} `yaml:"port"`
} `yaml:"production"`
} `yaml:"rest-api"`
}
有明显的子类型重复项。所以可以修剪。
第一关:
type Address struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
}
type MyConfig struct {
API struct {
Local Address `yaml:"local"`
Develop Address `yaml:"develop"`
Production Address `yaml:"production"`
} `yaml:"api"`
RestAPI struct {
Local Address `yaml:"local"`
Develop Address `yaml:"develop"`
Production Address `yaml:"production"`
} `yaml:"rest-api"`
}
第二次(也是最后一次)通过:
type Address struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
}
type Deployment struct {
Local Address `yaml:"local"`
Develop Address `yaml:"develop"`
Production Address `yaml:"production"`
}
type MyConfig struct {
API Deployment `yaml:"api"`
RestAPI Deployment `yaml:"rest-api"`
}
- 1 回答
- 0 关注
- 110 浏览
添加回答
举报