Simplify the marshaling of compose types.Config
- Add `Version` to `types.Config` - Add a new `Services` types (that is just `[]ServiceConfig`) and add `MarshalYAML` method on it. - Clean other top-level custom marshaling as `Services` is the only one required. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
@ -71,26 +71,24 @@ func (cd ConfigDetails) LookupEnv(key string) (string, bool) {
|
||||
// Config is a full compose file configuration
|
||||
type Config struct {
|
||||
Filename string `yaml:"-"`
|
||||
Services []ServiceConfig
|
||||
Version string
|
||||
Services Services
|
||||
Networks map[string]NetworkConfig
|
||||
Volumes map[string]VolumeConfig
|
||||
Secrets map[string]SecretConfig
|
||||
Configs map[string]ConfigObjConfig
|
||||
}
|
||||
|
||||
// MarshalYAML makes Config implement yaml.Marshaller
|
||||
func (c *Config) MarshalYAML() (interface{}, error) {
|
||||
// Services is a list of ServiceConfig
|
||||
type Services []ServiceConfig
|
||||
|
||||
// MarshalYAML makes Services implement yaml.Marshaller
|
||||
func (s Services) MarshalYAML() (interface{}, error) {
|
||||
services := map[string]ServiceConfig{}
|
||||
for _, service := range c.Services {
|
||||
for _, service := range s {
|
||||
services[service.Name] = service
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"services": services,
|
||||
"networks": c.Networks,
|
||||
"volumes": c.Volumes,
|
||||
"secrets": c.Secrets,
|
||||
"configs": c.Configs,
|
||||
}, nil
|
||||
return services, nil
|
||||
}
|
||||
|
||||
// ServiceConfig is the configuration of one service
|
||||
|
||||
Reference in New Issue
Block a user