I had installed go-1.6 in Ubuntu 16.04 LTS. I also had set up two different workspaces and the $GOPATH by specifying the location of both the workspaces in it.
But one of the workspaces(primary or main workspace) is working correctly while the other one(secondary workspace) is not working. I wish to use the secondary workspace for practising web app development in golang and the primary one for my projects. Both these workspaces have different packages in them as I am using them for different purposes. While working with the secondary workspace, I am getting errors like 'package not found' when I import packages in my programs . The 'go build' tool is looking for those packages in the primary workspace but they are present in secondary workspace. I am using Atom editor by GitHub.
Even when I install packages using 'go get', the packages are installed in the primary workspace.
The 'go environment variables' are as follows :-
gkv@GKVInnovations:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/gkv/Desktop/goWorkspace:/home/gkv/Desktop/Business/Backend"
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
Location of the primary workspace :- /home/gkv/Desktop/goWorkspace
Location of the secondary workspace :- /home/gkv/Desktop/Business/Backend
Please help me to resolve this issue and improve my workflow!
You are using Atom, which makes it harder to change GOPATH.
Go searches each directory listed in GOPATH to find source code, but new packages are always downloaded into the first directory in the list.
From https://golang.org/cmd/go/#hdr-GOPATH_environment_variable
Even though the GOPATH may be a list of directories, it is generally correct and sufficient to use a single GOPATH for all Go code on your machine. Since all packages retrieved with "go get" have a unique URL (and thus a unique path on disk), having more than one GOPATH is almost never necessary when building with the Go tool.
From https://github.com/golang/go/wiki/GOPATH#use-a-single-gopath
I use go for a client with specific packages and personally on lighter project. It's on the same computer. I mostly use go get for both of them.
By default I have an export GOPATH=~/path/to/pro
in my ~/.bashrc
. And when I want to work on my personal project, I export GOPATH=~/path/to/perso
.
As I use multiple desktops view (workspace) in unity, I let 1 workspace with a terminal with the right GOPATH in it and tinker in it