Is a symbolic link to the GOPATH folder common practice?

My git projects are stored here:

~/dev/git/project1 ... 

I'm starting a golang project, and since GOPATH is used to use it, is it common practice to create a symbolic link from my git path to GOPATH projects?

+5
source share
2 answers

Due to dependency issues between packages for GOPATH, a symlink was used. However, the GOPATH framework always assumed that it should be used for several projects, and the GOPATH symbolic link was discouraged by the developers.

In the latest version (1.6), however, they finalized the solution to the dependency problem (experimentally introduced in 1.5) in the form of a folder named vendor/ located at the top level of your package ( ) This folder will be searched before the regular GOPATH for the package used by the import statement.

There are various tools for optimizing the dependency process, such as godep or glide , which makes using the vendor/ folder much less time consuming than GOPATH GOPATH . Using a vendor package is also better reproducible than symbolic dependencies, ensuring your package works for everyone.

Therefore, I would advise you not to reference your GOPATH and use this recently introduced standard.

+3
source

As a result, I create my own GOPATH in the go project, which I want to keep isolated from my usual global $GOPATH .

I make a " b " script (in the project root folder) which:

  • check if src exists (in the project folder, here in ~/dev/git/project1 ): if it doesn't,
  • check if src / mypackage exists: if not, if creates a symbolic link src/mypackage -> ~/dev/git/project1 .
  • called with an alias: alias b='. ./b' alias b='. ./b'

So the same ' b ' (short for 'build') goes into ~/dev/git/project1/src/mypackage and does go install .
If you have a main package that will create a binary in ~/dev/git/project1/bin .

Thus, each of my projects remains autonomous, and is not lost in the sea of ​​other go packages in my regular $GOPATH/src . I reserve the global $GOPATH for global projects, which helps me to develop in go: golang.org/x/tools/cmd/... , github.com/fzipp/gocyclo and the like (other linters).


In other words, I am not symbolically GOPATH .
I really associate my package inside my project with a local GOPATH (local to the specified project), but GOPATH itself is a fixed folder (again specific to my project), defined as usual, without any symbolic link)

And it is perfectly compatible with the provider folder for the source dependency provider.


 alias b='. ./b' cd /path/to/my/project b: #!/bin/sh if [ ! -e src ]; then mkdir src ; fi if [ ! -e src/myproject ]; then ln -s /path/to/my/project src/myproject; fi cd src/myproject go install cd ../.. 
+1
source

Source: https://habr.com/ru/post/1247072/


All Articles