如何设置特定的GOPATH?

I have my go installed with ubuntu package. Basics library (fmt etc.) are working correctly.

But I have a real project in /var/www/mygoproject with multiple subfolder ex:

  • ./subfolder1
  • ./lib1
  • ./lib2
  • ./subfolder2

subfolderX contain different go applications and libX contain shared code.

I would like, in subfolderX use import "lib1/package-inside" but I always get the imported and not used error.

What I have to do ?


edit: code of /var/www/project/subproject/folder/alpha.go

package main

import (
    "subprojectA/folder/apackage" //doesnt work
    "./apackage" //works but not the cleanest
)

func main() {

    var sr interface{}
    sr = "tmp"

    apackage.Run(sr)
}

The go build system, in the first approximation, resolves import path pth by looking for package named $(basename pth) in directory $GOPATH/src/pth.

It seems to me you're missing the /src/ part.

Useful discussion of GOPATH can be found eg. here, another here