I was wondering if there is a way to automatically download all the imports.
So let's assume I need to use github.com/gorilla/mux
and several other packages in my code base. Should I manually go to my ~/go/src
and run go get repo
or is there a smarter way of doing dependency management. I am using Goland IDE for my development.
相关问题
- Golang mongodb aggregation
- How to flatten out a nested json structure in go
- how to install private repo using glide golang
- How to convert a string to a byte array which is c
- IntelliJ 2017.1.2 GOLANG debug does not work on br
There are several approaces:
go get github.com/gorilla/mux
which will download sources in your$GOPATH
and will be resolved automatically when compilingIf you want a good and stable solution, use
dep
(.First you have to install it, then run:You will see a new folder
vendor
in your project and 2 new dependency configuration filesGopkg.lock
andGopkg.toml
. Read more about godep here.Then run your main file as usual.
You can use
dep
package manager which will go through your code and automatically import all the packages you use in you code. If you are working with >go1.11 I would suggest to use newly addedgo mod
.You can download all imported pkgs and their dependencies by running
go get
from the command line.I'm using Goland too. When imports can't be found (ie the import path is highlighted in red), you can place your typing caret over it and press
alt + enter
and selectgo get ...
from the popup window to automatically import.