Этот онлайн-ресурс поможет вам на полпути:
https://mengzhuo.github.io/yaml-to-go/
Вставка вашего 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"`
}