Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer list format for extra_hosts to preserve backward compatibility #326

Merged
merged 1 commit into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion loader/full-example.yml
Expand Up @@ -160,8 +160,8 @@ services:
# somehost: "162.242.195.82"
# otherhost: "50.31.209.229"
extra_hosts:
- "somehost:162.242.195.82"
- "otherhost:50.31.209.229"
- "somehost:162.242.195.82"

hostname: foo

Expand Down
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
- otherhost:50.31.209.229
- somehost:162.242.195.82
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": [
"otherhost:50.31.209.229",
"somehost:162.242.195.82"
],
"hostname": "foo",
"healthcheck": {
"test": [
Expand Down
12 changes: 12 additions & 0 deletions types/types.go
Expand Up @@ -539,6 +539,18 @@ func (h HostsList) AsList() []string {
return l
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a sort.Strings to ensure stable output?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice suggestion!

}

func (h HostsList) MarshalYAML() (interface{}, error) {
list := h.AsList()
sort.Strings(list)
return list, nil
}

func (h HostsList) MarshalJSON() ([]byte, error) {
list := h.AsList()
sort.Strings(list)
return json.Marshal(list)
}

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