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

Is there an alternative way to init() here? #1335

Closed
frederikhors opened this issue Feb 3, 2021 · 5 comments
Closed

Is there an alternative way to init() here? #1335

frederikhors opened this issue Feb 3, 2021 · 5 comments

Comments

@frederikhors
Copy link

I'm using this code:

func init() {
  rootCmd.AddCommand(versionCmd)
}

but the linter: https://github.com/leighmcculloch/gochecknoinits in https://golangci-lint.run/usage/linters/ alerts me with:

don't use `init` function

How to fix this?

Is there an alternative way to init() here?

@github-actions
Copy link

github-actions bot commented Apr 5, 2021

This issue is being marked as stale due to a long period of inactivity

@frederikhors
Copy link
Author

No stale.

@MichaelMure
Copy link
Contributor

Have a look at #1336 (comment)

@johnSchnake
Copy link
Collaborator

Closing since the larger discussion and alternatives are in the linked issue above.

@mloskot
Copy link

mloskot commented Mar 15, 2024

The simple pattern of constructor/factory functions may help, it also improves testability, see:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants