Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut to install libraries in Goland

Tags:

go

goland

I'm following the instructions in https://golang.org/doc/code.html#Library and trying to use Goland. I'm surprised though that I can't find a fast way to install the library I'm writing. According to the tutorial, you should use install to install your code in the pkg or bin folders, yet I can't find a way to do this in Goland other than writing it in the console. What am I missing?

like image 720
uzilan Avatar asked Dec 24 '22 10:12

uzilan


1 Answers

There are two ways to import Go packages using GoLand:

  1. copy-paste the code that needs the package into the IDE and then on the import declaration use Show Intention to see the list of actions available and choose the first one, go get -t <package-name>/...
  2. copy the URL of the Github repository into your clipboard, switch to the IDE and use the pop-up to run go get on the package. The pop-up disappears after a few seconds.

I've attached the image which shows these options. import packages in GoLand

This will download libraries in the correct GOPATH directory and run go install as part of the go get action.

As for installing the libraries that you are developing in GOPATH/pkg, there is no need for that, as soon as you run any configuration from the IDE, be it an application or a test that depend on those libraries, the IDE will install those libraries as well.

like image 73
dlsniper Avatar answered Jan 03 '23 08:01

dlsniper