I cannot figure out how to initialize a nested struct. Find an example here: http://play.golang.org/p/NL6VXdHrjh
package main
type Configuration struct {
Val string
Proxy struct {
Address string
Port string
}
}
func main() {
c := &Configuration{
Val: "test",
Proxy: {
Address: "addr",
Port: "80",
},
}
}
One gotcha arises when you want to instantiate a public type defined in an external package and that type embeds other types that are private.
Example:
How do you instantiate a
Duck
in your own program? Here's the best I could come up with: