Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Two commands:

go mod init mymodulename

go build

This will download all the dependencies needed automatically.

You can also do this (from scratch as well):

go mod init mymodulename

go run main.go

And it will still download the dependencies.

If you use a modulename like github.com/dana321/test you can include a subfolder of your project by importing github.com/dana321/test/mysubfolder for example

If you bring down the wrong version (ie. an older) version of a module, just edit the go.mod file and modify the version (after the space where the url is) and change it to master on the line where the module is. When you next run go build or go run it will re-download and re-populate the line(s) you've changed in go.mod with the latest version.

There really isn't much else you need to know!



There is if you want to vendor your dependencies, which given my experience with golang dependency management over the years, I’ll be doing for the foreseeable future.

This guide outlines the set of incantations required to accomplish that & frankly having fought through figuring it out myself from the doco, this would have saved me a bunch of time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: