Basic struct composition is simple and handled well by the extraConfig package:
type ContainerNetwork struct {
metadata.ContainerNetwork
PortGroup object.NetworkReference
}
referencing that extended struct in place of the base type, such as:
type Configuration struct {
// The default bridge network supplied for the Virtual Container Host
BridgeNetwork string `vic:"0.1" scope:"read-only" key:"bridge_network"`
// Published networks available for containers to join, keyed by consumption name
ContainerNetworks map[string]*ContainerNetwork `vic:"0.1" scope:"read-only" key:"container_networks"`
}
is more problematic - this is because when walking that structure with reflection the ContainerNetwork structure appears as deeper in the hierarchy and the generated keys reflect this - the contents of metadata.ContainerNetwork would be keyed as:
./container_networks|mapkey/ContainerNetwork/... instead of ./container_networks|mapkey/...
To address this we need an inline annotation that inhibits that extra depth - a naïve implementation is very simple, but a correct one will need to check for name collisions with the extended struct. While there are ways to do so a fault if detected instead of trying to handle it neatly is preferable on the first pass.
Basic struct composition is simple and handled well by the extraConfig package:
referencing that extended struct in place of the base type, such as:
is more problematic - this is because when walking that structure with reflection the ContainerNetwork structure appears as deeper in the hierarchy and the generated keys reflect this - the contents of metadata.ContainerNetwork would be keyed as:
./container_networks|mapkey/ContainerNetwork/...
instead of./container_networks|mapkey/...
To address this we need an
inline
annotation that inhibits that extra depth - a naïve implementation is very simple, but a correct one will need to check for name collisions with the extended struct. While there are ways to do so a fault if detected instead of trying to handle it neatly is preferable on the first pass.