Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Change cloud.Cloud.Regions to slice #4469
Conversation
waigani
and others
added some commits
Jan 7, 2016
wallyworld
reviewed
Feb 19, 2016
| // Regions are the regions available in the cloud. | ||
| - Regions map[string]Region `yaml:"regions,omitempty"` | ||
| + // | ||
| + // Regions is a slice, and not a mpa, because order is important: |
wallyworld
reviewed
Feb 19, 2016
| @@ -134,28 +173,91 @@ func PublicCloudMetadata(searchPath ...string) (result map[string]Cloud, fallbac | ||
| return clouds, true, err | ||
| } | ||
| +var logger = loggo.GetLogger("juju.cloud") |
wallyworld
reviewed
Feb 19, 2016
| + logger.Debugf("%v", cloud.Regions) | ||
| + for _, item := range cloud.Regions.Slice { | ||
| + name := fmt.Sprint(item.Key) | ||
| + r := cloud.Regions.Map[name] |
wallyworld
Feb 19, 2016
Owner
why can't we use item.Value here?
I don't get why we need both a Map and a Slice
axw
Feb 19, 2016
Member
This means I don't have to extract map items explicitly, so easier to maintain (Region may grow fields). The MapSlice is used only for the key ordering.
wallyworld
Feb 19, 2016
Owner
r := item.Value.(*region)
won't work?
var regions []Region
if len(cloud.Regions.Slice) > 0 {
for _, item := range cloud.Regions.Slice {
name := fmt.Sprint(item.Key)
r := item.Value.(*region)
regions = append(regions, Region{
name, r.Endpoint, r.StorageEndpoint,
})
}
}
wallyworld
reviewed
Feb 19, 2016
| +// is populated so we can identify the first map item, which | ||
| +// becomes the default region for the cloud. | ||
| +type regions struct { | ||
| + Map map[string]*region |
wallyworld
Feb 19, 2016
Owner
there's no yaml tags here - are Map and Slice implicitly support by goyaml.v2?
axw
added some commits
Feb 18, 2016
|
Retargeting to master. |
axw
closed this
Feb 19, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
axw commentedFeb 19, 2016
No description provided.