Not resolving dependency in vendor directory
Asked Answered
M

1

6

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"
)
Mckinnie answered 20/3, 2016 at 21:27 Comment(1)
Why do you have bin, pkg and src in your project directory? Your project should be located at its import path. What is the overall structure here?Myotonia
P
5

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.

Prebend answered 21/3, 2016 at 2:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.