I had the same problem a month ago. I solved it by using the following steps.
My package name is called alpaca
My working directory (code) is /home/pksunkara/coding/alpaca
$ gvm use go1.2
Now using version go1.2
$ echo $GOPATH
/usr/local/lib/gvm/pkgsets/go1.2/global
$ echo $GOROOT
/usr/local/lib/gvm/gos/go1.2
To fix the issue, I did this
$ mkdir -p $GOPATH/src/github.com/pksunkara
$ ln -s /home/pksunkara/coding/alpaca $GOPATH/src/github.com/pksunkara/alpaca
Basically I have to link the current working folder into the $GOPATH/src
folder and the resultant package path for alpaca
became github.com/pksunkara/alpaca
.
Now, the go test & cover works as following
$ go test -coverprofile=coverage.out github.com/pksunkara/alpaca
$ go tool cover -html=coverage.out
THIS IS IMPORTANT
I stumbled a lot to fix this. I have attempted all kind of things including the ones you attempted. I understood the problem by reading about code organization in golang which should be a must read for everyone working with go.
The code organization mentioned here is very important to work with golang.
Package paths are important for golang. And you should never use local path when importing in golang. They will work but it is not recommended.
Let's assume your package name is model
. You can simply link the model
directory to $GOPATH/src/model
and then you will have a package path named model
which you can import using import "model"
. But to avoid collisions, go recommends using a bigger package path name.
I would recommend you to link it to $GOPATH/src/bill.com/server/model
and import it as import "bill.com/server/model"
. Similarily with ./query
and ./util
you have.
If you still have doubts, please ask. I will try to explain more.