Home > front end >  How to deal with global external tools in Go?
How to deal with global external tools in Go?

Time:07-24

I come from Node environment, where we have package.json to deal with dependencies. In Go we have go.mod, which is great, but some tools ask us to install their binaries globally instead of setting as a dependency of my project, such as golangci-lint. In Node, for example, we have eslint, which is installed automatically for us when we ask to install or dependencies.

What bothers me is when someone clones my project or I'm in a CI/CD environment, they have to manually install those dependencies.

What's the best practice to deal with tools like golangci-lint? Am I doing something wrong?

CodePudding user response:

Go doesn't prescribe how to install arbitrary executables on any target platform because there are so many different possible ways to do it, even on the same operating system (consider the many different Linux distributions and their various package managers).

As such, it's up to authors to advise users how to best install their software.

For example, the golangci-lint utility you mentioned provides its own installation instructions. Note also that the "Why?" items in the "Install from Source" section explain some of the challenges in a one-size-fits-all solution such as go get or go install.

CodePudding user response:

For external dependencies you could make proper Makefile targets and tools with how to Readme.md file with steps to install etc.

or build docker compose files to the repository if you want to include all external tools using Docker.

for internal dependancy management use:

1.go mod tidy

2.go mod vendor

this creates a vendor directory in the projects and keep all packages downloaded inside the vendor directory.

make sure to run these commands whenever you change some dependencies or start using new packages.

  •  Tags:  
  • go
  • Related