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

Export dockerCompose type so consumers can store it in a variable and call Down #2907

Open
mdelapenya opened this issue Dec 2, 2024 · 6 comments · May be fixed by #2953
Open

Export dockerCompose type so consumers can store it in a variable and call Down #2907

mdelapenya opened this issue Dec 2, 2024 · 6 comments · May be fixed by #2953
Labels
compose Docker Compose.

Comments

@mdelapenya
Copy link
Member

No description provided.

@mdelapenya mdelapenya converted this from a draft issue Dec 2, 2024
@mdelapenya mdelapenya added the compose Docker Compose. label Dec 2, 2024
@jasonyunicorn
Copy link
Contributor

@mdelapenya I'd like to volunteer to pick this up.

@mdelapenya
Copy link
Member Author

@jasonyunicorn please do it 🙏 If you don't know where to start, please open the initial PR in draft and we can iterate/discuss around it.

Thanks for volunteering!

@jasonyunicorn
Copy link
Contributor

I created a PR which exports the DockerCompose type, but @stevenh has brought to my attention that this isn't necessary, since the exported methods on dockerCompose can still be accessed.

Should this Issue (and PR) be closed?

@KenjiTakahashi
Copy link

KenjiTakahashi commented Jan 30, 2025

I'm not a maintainer, but a user interested in this.
I'd say if the API exposes a function that returns the type (in this case NewDockerCompose* return *dockerCompose), this type should also be exposed.
Otherwise it is not possible to pass returned instances to other functions or store them in structs. Generally use them in places where specifying the type is necessary.
[Another way of handling this would be to create an interface and expose/return that instead, if it is not desirable to expose the struct directly. Don't think it is necessary here, but up to you.]

Edit: This is even considered a "warning" in the revive linter: https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return.

@xbc5
Copy link

xbc5 commented Jan 31, 2025

@KenjiTakahashi @mdelapenya @jasonyunicorn

dockerCompose satisfies the ComposeStack interface.

func New() (tc.ComposeStack, error) {
	return tc.NewDockerCompose("...")
}

@stevenh
Copy link
Contributor

stevenh commented Jan 31, 2025

@KenjiTakahashi is right, returning private types is a code smell.

If we update the reason for the PR to address that instead of the current reason, happy to accept that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compose Docker Compose.
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

5 participants