Skip to content

Commit

Permalink
prefer list format for extra_hosts to preserve backward compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Dec 6, 2022
1 parent d61c32f commit e8bd5fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 6 additions & 6 deletions loader/full-struct_test.go
Expand Up @@ -716,8 +716,8 @@ services:
- project_db_1:mysql
- project_db_1:postgresql
extra_hosts:
otherhost: 50.31.209.229
somehost: 162.242.195.82
- somehost:162.242.195.82
- otherhost:50.31.209.229
hostname: foo
healthcheck:
test:
Expand Down Expand Up @@ -1302,10 +1302,10 @@ func fullExampleJSON(workingDir, homeDir string) string {
"project_db_1:mysql",
"project_db_1:postgresql"
],
"extra_hosts": {
"otherhost": "50.31.209.229",
"somehost": "162.242.195.82"
},
"extra_hosts": [
"somehost:162.242.195.82",
"otherhost:50.31.209.229"
],
"hostname": "foo",
"healthcheck": {
"test": [
Expand Down
12 changes: 10 additions & 2 deletions types/types.go
Expand Up @@ -354,12 +354,12 @@ type ThrottleDevice struct {
// ShellCommand is a string or list of string args.
//
// When marshaled to YAML, nil command fields will be omitted if `omitempty`
// is specified as a struct tag. Explicitly empty commands (i.e. `[]` or `''`)
// is specified as a struct tag. Explicitly empty commands (i.e. `[]` or ``)
// will serialize to an empty array (`[]`).
//
// When marshaled to JSON, the `omitempty` struct must NOT be specified.
// If the command field is nil, it will be serialized as `null`.
// Explicitly empty commands (i.e. `[]` or `''`) will serialize to an empty
// Explicitly empty commands (i.e. `[]` or ``) will serialize to an empty
// array (`[]`).
//
// The distinction between nil and explicitly empty is important to distinguish
Expand Down Expand Up @@ -539,6 +539,14 @@ func (h HostsList) AsList() []string {
return l
}

func (h HostsList) MarshalYAML() (interface{}, error) {
return h.AsList(), nil
}

func (h HostsList) MarshalJSON() ([]byte, error) {
return json.Marshal(h.AsList())
}

// LoggingConfig the logging configuration for a service
type LoggingConfig struct {
Driver string `yaml:",omitempty" json:"driver,omitempty"`
Expand Down

0 comments on commit e8bd5fe

Please sign in to comment.