Although I've been using language for more than a couple of months now, I hadn't seen myself with this need. What I want is to initialize the structure that I show below (basically initialize Project and then, inside, aaa, bbb and ccc structs). My question is whether I can really initialize it without making an unmarshall.
type example struct {
Name string `yaml:"name" json:"name"`
Key string `yaml:"key" json:"key"`
Version string `yaml:"version" json:"version"`
Project []struct {
Name string `yaml:"name" json:"name"`
aaa struct {
Name string `yaml:"name" json:"name"`
Key string `yaml:"key" json:"key"`
xxx struct {
Version string `yaml:"version" json:"version"`
} `yaml:"xxx" json:"xxx"`
zzz struct {
Version string `yaml:"version" json:"version"`
} `yaml:"zzz" json:"zzz"`
} `yaml:"aaa" json:"aaa"`
bbb struct {
Name string `yaml:"name" json:"name"`
Key string `yaml:"key" json:"key"`
xxx struct {
Version string `yaml:"version" json:"version"`
} `yaml:"xxx" json:"xxx"`
zzz struct {
Version string `yaml:"version" json:"version"`
} `yaml:"zzz" json:"zzz"`
} `yaml:"bbb" json:"bbb"`
ccc struct {
Name string `yaml:"name" json:"name"`
Key string `yaml:"key" json:"key"`
xxx struct {
Version string `yaml:"version" json:"version"`
} `yaml:"xxx" json:"xxx"`
zzz struct {
Version string `yaml:"version" json:"version"`
} `yaml:"zzz" json:"zzz"`
} `yaml:"ccc" json:"ccc"`
} `yaml:"project" json:"project"`
}
I know I could do it in some way similar to the following. But I try to know the language better.
type example struct {
Name string `yaml:"name" json:"name"`
Project proyectos }
type proyectos structs{
[] proyecto
}
type proyecto struct{
Name string `yaml:"name" json:"name"`
aaa struct {
.....
} `yaml:"project" json:"project"`
I appreciate anyone who can give me a hint about this with an example.
Thank you.