Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not resolving dependency in vendor directory

I'm running go1.6 and am getting the follow error when running "go build" in GOPATH (/Users/bweidlich/Projects/go)

main.go:6:2: cannot find package "github.com/spf13/viper" in any of:
/usr/local/go/src/github.com/spf13/viper (from $GOROOT)
/Users/bweidlich/Projects/go/src/github.com/spf13/viper (from $GOPATH)

Project structure:

bin/
glide.lock
glide.yaml
go.iml
logs/
main.go
pkg/
src/
vendor/
      github.com/
                 deckarep/gosx-notifier
                 spf13/viper
                 gizak/termui

main.go

package main

import (
    "fmt"
    "github.com/gizak/termui" <--- doesn't resolve
    "github.com/spf13/viper"  <--- doesn't resolve
    "log"
    "bweidlich/dash"
    "net/http"
    "os"
    "os/exec"
    "time"
)
like image 929
bjoern Avatar asked Mar 20 '16 21:03

bjoern


1 Answers

Your main.go file needs to be inside a workspace (that is, inside gopath) for its dependencies to be vendored. As a test, try putting your main.go inside a fake path and see if the vendored deps are found:

$GOPATH/src/
   example.com/
     main.go
   vendor/
     github.com/
       spf13/viper/
       gizak/termui/

In general, you don't want to store any code in your gopath outside its root src directory. That is, you should echo the structure that go get would use when creating the directories.

like image 180
djd Avatar answered Sep 30 '22 15:09

djd