Closed perhallgren closed 6 years ago
Duplicate to #116
This is actually the inverse of #116.
The problem in #116 was that we imported context from the standard library so users of an old version of gomock had compilation problems. To solve that we imported golang.org/x/net/context instead. This bug is saying that the compilation failed because golang.org/x/net/context was not found.
This issue is easily fixed by running "go get".
@zut please try "go get" and report back.
Hi!
I'm rather new to go, so not quite sure what's important to know to track this down.
I installed mockgen via go get github.com/golang/mock/mockgen
this week (Thursday evening or Friday morning). This (I think) downloaded
$GOPATH/src/github.com/golang/mock/gomock/controller.go
, with the incorrect version containing the golang.org/x/net/context
path.
I modified it to compile and worked on for a while. Then I did dep ensure
for other reasons, which put a new copy in vendor/github.com/golang/mock/gomock/controller.go
. This new copy has the correct import statements.
I don't know if I can find the version in the sources somehow to know what go get
downloaded, but the files currently say
Old, seemingly broken, version:
import (
"fmt"
"context" // this line said "golang.org/x/net/context" when I downloaded it
"reflect"
"runtime"
"sync"
)
New, correct version:
import (
"fmt"
"reflect"
"sync"
)
Older versions of Go (pre 1.7) didn't have a "context" package. If we import "context" then gomock breaks for them. There exists an external package, "golang.org/x/net/context", which is the same package. Using that works for both new and old versions of Go.
The problem that you ran into was that gomock has a dependency on that package but you hadn't downloaded that package. I believe that the go tool is supposed to get dependencies for you automatically but I'm not sure of the details. That's why I suggested running go get
(with the unmodified code) to see if the go tool downloads the dependencies for you.
Do you mean I should first do go get github.com/golang/mock/mockgen
with the lib specified, then just go get
without parameters?
Right now if I run go get
, I don't get anything downloaded into $GOPATH/src/golang.org/x/net
.
You would run go get github.com/golang/mock
then cd github.com/golang/mock/gomock
then go get
. This sequence worked for me.
I think the root of this issue is that gomock has an external dependency but I think it should be fine for gomock to have an external dependency.
I'm open to suggestions though on how to make this easier, especially if there are common practices for managing external deps in Go projects.
Closing for now. Feel free to re-open.
getting the error as show in the above image. I have all the packages in the directory but still getting the error
@praveen691cs I'm not seeing that github.com/golang/mock is referenced in that screen shot. Am I missing it?
sorry i didn't get you. could you please explain it a bit more. why should we refer refer to github.com/golang/mock?? It is a new app while using google sheets api i am getting that error even though the packages are availabe in the current directory
@praveen691cs I am asking if you are suggesting controller.go
from github.com/golang/mock
is importing golang.org/x/net/context
?
In
github.com/golang/mock/gomock/controller.go
I get an issue:This seems to be resolved by instead just importing
context
, as per https://stackoverflow.com/questions/42802278/install-context-package-in-golang. With an updated controller.go with lines 58-64 as below, it works fine for me.(running go version go1.9 darwin/amd64)