yowmamasita
yowmamasita

Reputation: 4960

vendor directory not being used to resolve imports on go build

I'm in the process of relearning Go. I installed the latest Go version (1.7.1) using gvm and I am looking to build a simple rest api app using gin. I installed it using glide get https://github.com/gin-gonic/gin (glide) and that created a "vendor" folder on my project root. Running my app though, go run main.go, I encounter this error

main.go:3:8: cannot find package "github.com/gin-gonic/gin" in any of:
    /home/yowmamasita/.gvm/gos/go1.6.3/src/github.com/gin-gonic/gin (from $GOROOT)
    /home/yowmamasita/.gvm/pkgsets/go1.6.3/global/src/github.com/gin-gonic/gin (from $GOPATH)

It is not resolving the "vendor" directory glide just created

.
├── glide.lock
├── glide.yaml
├── main.go
├── README.md
└── vendor
    └── github.com
        └── gin-gonic
            └── gin

Not sure what's happening here, I thought after 1.5, it should be able to resolve imports from "vendor" directories without doing anything. I even added my projects folder on my $GOPATH

/home/yowmamasita/.gvm/pkgsets/go1.7.1/global:/home/yowmamasita/goprojects

What am I doing wrong here? I tried 1.6.3 too and I get the same error.

Upvotes: 1

Views: 2871

Answers (1)

putu
putu

Reputation: 6444

Please make sure:

  1. Add the workspace (/home/yowmamasita/goprojects) to $GOPATH variable.
  2. Typically under workspace there will be three directories which are bin, pkg and src. More details
  3. You can omit pkg and bin, but the project which is using vendor packages or your custom package must be placed under $GOPATH/src, otherwise go compiler will not recognized it.

More discussions can be found here and here

The structure should look like:

 $GOPATH
 └── src
     └── YOURPROJECT1
            ├── source codes #1
            └── vendor/

     └── YOURPROJECT2
            ├── source codes #2
            └── vendor/

Upvotes: 2

Related Questions