go - How to initialize nested struct in golang? -
type important struct { client string `json:"client"` response summary `json:"response"`
}
type summary struct { name string `json:"name"` metadata clientdata `json:"metadata"` } type clientdata struct { income string `json:"income"` } v := &important{ client: "xyz", response: summary[{ name: "test", metadata: clientdata { "404040"}, } }]
//error: cannot use summary{ name: "test", metadata: clientdata { "404040"}, } (type summary) type []summary more...
what doing wrong here?
to put simply, goofed syntax of slice literal slightly. mistake logical, sadly doesn't work.
the following fixed version:
v := &important{ client: "xyz", response: []summary{ { name: "test", metadata: clientdata { "404040"}, }, }, }
a slice literal defined so:
[]type{ items... }
Comments
Post a Comment