make Services a map[string]ServiceConfig to reflect yaml structure#483
make Services a map[string]ServiceConfig to reflect yaml structure#483ndeloof merged 1 commit intocompose-spec:mainfrom
Conversation
793fb23 to
c4a2646
Compare
milas
left a comment
There was a problem hiding this comment.
LGTM, just one point of concern where we're returning p.Services directly
Beyond that, we should think about our iteration patterns to avoid weirdness from random Go map iteration order
| if len(names) == 0 { | ||
| return p.Services, nil | ||
| } |
There was a problem hiding this comment.
I think we should make a copy of the map here – if a caller ends up mutating the result, they'll be unintentionally changing the project
There was a problem hiding this comment.
This issue we already have with networks/volumes/secrets/configs
A global "immutability" refactoring is under consideration, but will come as a future effort
Please note if we try to encapsulate the map nature of this, we will have to manage the yaml unmarshaling, so we could consider to offer "mutation-safe" iterator Services.Each(func(name, ServiceConfig)), but won't preserve third-party to use a plain range. Please also note mutating the model could be required by user
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
the docker/cli compose parser we inherited as compose-go used a
[]ServiceConfigto map to yamlservices. I'm not sure what was the reason for this design decision, and propose we adopt a naturalmap[string]ServiceConfigtype.For convenience,
ServiceConfig.Nameis set to map key