Where is a good place for $ GOPATH?

I am working on a project in Go that requires several external libraries, such as the MySQL driver, image management library, etc. I now have $GOPATHfor / usr / lib / go / src, which puts any downloaded packages in / usr / lib / go / src / src, which clearly doesn't seem right. If I installed $GOPATHin / usr / lib / go, I get an error message that $GOPATHcannot be installed in the same directory as $GOROOT. So I have to put GOPATH=/path/to/my/project/libbuild.sh in my file, and when I submit my git repository, put lib / in my .gitignore?

I understand that this is probably a stupid question. It works great, as it is now, I'm just wondering if this is bad.

+4
source share
1 answer

$ GOPATH can indeed be any location of your choice (with some exceptions) if the compiler knows where to find it. If you change it, just make sure you update the path with

export GOPATH=/path/to/gopath

My personal preference is to leave $ GOPATH separate from my code unless I write a package that is intended to be imported through go get <repo path>, in which case I will write the code in

$GOPATH/src/<repo path>

which is the standard location that the package stores when used go get <repo path>

+7
source

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


All Articles