I've been trying to solve this problem for the past two hours. I cannot, for the life of me, understand how the folks who developed Go did such a fine job with the language but such a terrible job with package management.
Here is my go env
output:
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/<me>/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/<me>/Documents/Proj/go"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z4/b3lxy_51405_b8pb_680l4xh0000gn/T/go-build063693521=/tmp/go-build -gno-record-gcc-switches -fno-common"
Notice that my GOPATH
and GOROOT
are set.
Here is the structure of my go workspace (/Users/<me>/Documents/Proj/go
):
go/
|-bin/
|-pkg/
|-src/
|--github.com/
|--user/
|--myproject/
|--client/
|--client.go
|--main.go
Here is my client.go
file:
// client.go
package client
type MyClient struct {}
this is my main.go
file:
// main.go
package main
import "client"
func main() {}
When I run go build
in the project root, I get this error:
main.go:4:2: cannot find package "client" in any of:
/usr/local/opt/go/libexec/src/transport (from $GOROOT)
/Users/<me>/Documents/Proj/go/src/transport (from $GOPATH)
The first time this happened, I tried to correct the path above:
// main.go
package main
import "github.com/user/myproject/client"
func main() {}
Then I got this error:
main.go:4:2: cannot find package "client" in any of:
/usr/local/opt/go/libexec/src/transport (from $GOROOT)
/Users/<me>/Documents/Proj/go/src/github.com/user/myproject/transport (from $GOPATH)
Which is bizarre, since the package exists at that exact path.
What am I doing wrong??