1 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊
粘貼您的 yaml 會(huì)產(chǎn)生以下結(jié)果:
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"`
}
有明顯的子類型重復(fù)項(xiàng)。所以可以修剪。
第一關(guān):
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 關(guān)注
- 156 瀏覽
添加回答
舉報(bào)