What is the golang command that is equivalent to npm install
npm install
downloads all the dependencies listed in the package.json file.
Having said that, what is the command that downloads all the dependencies in the go.mod file?
CodePudding user response:
If you have only a go.mod and you have Go 1.16 or later:
- If you just want to run your code, use
go build
orgo run .
- your dependencies will be downloaded and built automatically - If you want to save a copy of your dependencies locally, use
go mod vendor
Both the above will create a go.sum file (this is maintained by the Go Tools - you can ignore it)
The vendor command will create a vendor folder with a copy of all the source code from your dependencies. Note: If you do use the vendor approach, you will need to run go mod vendor
if there is a change in your dependencies, so that a copy is downloaded to the vendor folder. The advantage is your code will build without an internet connection. The disadvantage is you need to keep it up to date.
That should get you started for every day use.
If you'd like to know all about modules, this is a good source.