Skip to content

api/types/container: create type for changes endpoint#45353

Merged
thaJeztah merged 2 commits intomoby:masterfrom
thaJeztah:api_container_change_type
May 4, 2023
Merged

api/types/container: create type for changes endpoint#45353
thaJeztah merged 2 commits intomoby:masterfrom
thaJeztah:api_container_change_type

Conversation

@thaJeztah
Copy link
Member

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added this to the 24.0.0 milestone Apr 17, 2023
@thaJeztah thaJeztah force-pushed the api_container_change_type branch from 520c5f8 to de63510 Compare April 17, 2023 21:56
@rumpl rumpl modified the milestones: 24.0.0, v-future Apr 24, 2023
@thaJeztah thaJeztah changed the title [WIP] api/types/container: create type for changes endpoint api/types/container: create type for changes endpoint Apr 29, 2023
@thaJeztah thaJeztah marked this pull request as ready for review April 29, 2023 18:34
@thaJeztah thaJeztah requested a review from tianon as a code owner April 29, 2023 18:34
@thaJeztah
Copy link
Member Author

@tianon @rumpl @vvoland ptal

case ChangeDelete:
return "D"
default:
return ""
Copy link
Member

Choose a reason for hiding this comment

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

Should we do something different here to make it more obvious when it's an unknown value?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was considering that; for now I stuck with what the CLI already used; #45235 (comment)

And wasn't sure what else to put here ("-" ? "?" ? <unknown> ?) WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

I personally like something really really verbose that'll definitely screw up formatting like <unknown> or <invalid> because it increases the chances that someone notices (because it's definitely an error somewhere if we run into that case) 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess the alternative could be to

  • not implement the stringer interface, and instead make this a Change() with a (string, error) return.
  • return strconv.Itoa() to return the numeric value

I do like the stringer interface though (is handy to have), and if we return an error, we also need to take into account "what if we add more options in future?" So yeah, perhaps <unknown> is the way to go 🤔

thaJeztah added 2 commits May 3, 2023 21:23
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- use gotest.tools for asserting
- check result returned

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the api_container_change_type branch from de63510 to 66cf0e3 Compare May 3, 2023 19:26
@thaJeztah
Copy link
Member Author

Fixed the test, and pushed a commit to slightly improve that test; https://github.com/moby/moby/compare/de63510d70071a034b03b79934c7e70fa294a9ef..66cf0e3f5575cace57219607d042cc1c4cd536d2

@thaJeztah
Copy link
Member Author

Thanks! I'll bring this one in, and will do a small follow-up to discuss/make the <unknown> (or other format) changes 👍

@thaJeztah thaJeztah merged commit 8a4b095 into moby:master May 4, 2023
@thaJeztah thaJeztah deleted the api_container_change_type branch May 4, 2023 17:48
@thaJeztah thaJeztah modified the milestones: v-future, 24.0.0 May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: define better type (enum) and remove archive.Changes from the API

4 participants