Golang 1.6 Cannot find packages in vendor folder - go

I'm on go version 1.6.2 and am trying to go build an application.
Several dependencies are located inside the vendor folder (e.g vendor/docker/libcompose/) but I get a cannot find package when trying to load them.
Here's an error message:
main.go:10:2: cannot find package "github.com/docker/libcompose/cli/command" in any of:
/usr/local/opt/go/libexec/src/github.com/docker/libcompose/cli/command (from $GOROOT)
/Users/ali/golang/src/github.com/docker/libcompose/cli/command (from $GOPATH)
What am I doing do wrong?
The doc says that packages put in the vendor folder are loaded automatically.

Looking at your example, the folder structure is wrong.
The package github.com/docker/libcompose should be in vendor/github.com/docker/libcompose not in vendor/docker/libcompose.
See more here.

Related

Error in compiling golang after migrating to centos

I was migrating my Golang programs from windows to Centos 7
It worked perfectly in Windows
but when I tried to compile on centos I get errors like
main.go:20:3: cannot find package "github.com/BurntSushi/toml" in any of:
/usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
/root/work/src/github.com/BurntSushi/toml (from $GOPATH)
main.go:15:3: cannot find package "github.com/dgrijalva/jwt-go" in any of:
/usr/local/go/src/github.com/dgrijalva/jwt-go (from $GOROOT)
/root/work/src/github.com/dgrijalva/jwt-go (from $GOPATH)
main.go:16:3: cannot find package "github.com/gwlkm_service/config" in any of:
/usr/local/go/src/github.com/gwlkm_service/config (from $GOROOT)
/root/work/src/github.com/gwlkm_service/config (from $GOPATH)
kinda new to centos so idk what to do
looks like you have configured your GOPATH, without Go Module, you can use go get [package path] to download imported packages.
go get github.com/BurntSushi/toml
go get github.com/dgrijalva/jwt-go
go get github.com/gwlkm_service/config
Precisely
your go installation on server seems in /usr/local/go and
your project is in /root/work
so all your dependencies should be either in /root/work/src or /usr/local/go/src
now coming to action check your GOPATH with running echo $GOPATH
assuming it is automatically set to /usr/local/go/src
If not then follow - How do I SET the GOPATH environment variable on Ubuntu? What file must I edit?
If everything is ok then in your folder run go mod init
this will create mod file which will help you in further installations
look into - https://blog.golang.org/using-go-modules
then run go get commands as above #beiping96 said
go get github.com/BurntSushi/toml
go get github.com/dgrijalva/jwt-go
go get github.com/gwlkm_service/config
NOTE - after completing above process you will generate go modules file(same as package.json) and in future you won't need to care about dependencies

how to import package from github

I'm trying to build a api using Go and I tried running a existing file from GitHub that I got from udemy course. I'm getting this kind of output:
C:\goworkspace\src\grpc-go-course-master\blog\blog_client>go run client.go
client.go:4:2: cannot find package "context" in any of:
C:\go\src\context (from $GOROOT)
C:\goworkspace\src\context (from $GOPATH)
..\..\..\golang.org\x\net\http2\not_go111.go:10:2: cannot find package "net/http/httptrace" in any of:
C:\go\src\net\http\httptrace (from $GOROOT)
C:\goworkspace\src\net\http\httptrace (from $GOPATH)
Could you suggest me what can cause this error?
In order to download the dependencies, you have to use the go get command:
go get -v -u github.com/alessiosavi/GoUtils
Change with the package that you need (in that repo you can find a bunch of 'utils' method).
If the project, instead, have the go.mod file, you have to type:
go clean
go build
By this way you are going to install the dependencies listed in the go.mod file.
For update the dependencies to the latest version:
go get -v -u all
go mod tidy
The above command looks for missing dependencies, adds them to go.mod, and installs them.

Problems with dependencies after setting up go dep

My project is located in $GOPATH/src/smp-cloudupload
I can run dep init without errors.
After that I cant compile the project anymore. One of the errors:
main/scs/scsApiGateway.go:5:2: cannot find package "_/home/dev/go/src/smp-cloudupload/vendor/github.com/dgrijalva/jwt-go" in any of:
/usr/lib/go-1.10/src/_/home/dev/go/src/smp-cloudupload/vendor/github.com/dgrijalva/jwt-go (from $GOROOT)
/home/dev/go/src/_/home/dev/go/src/smp-cloudupload/vendor/github.com/dgrijalva/jwt-go (from $GOPATH)
I am new to GO and I have a feeling, that there are either issues with my project structure or the GOPATH. The shown path is wrong. The correct path is: /home/dev/go/src/smp-cloudupload/vendor/github.com/dgrijalva/jwt-go
What am I doing wrong?
EDIT:
Output of echo $GOPATH:
dev#dev-VirtualBox:~/go/src/smp-cloudupload/main$ echo $GOPATH
/home/dev/go
I have no idea why there is a underscore in the path. The actual path of my project contains no underscores
I think this is resolved now. I was running into this problem:
https://github.com/Masterminds/glide/issues/602
After reading this:
https://thenewstack.io/understanding-golang-packages/
I setup my project structure as follows:
/home/dev/go/src/smp-cloudupload
pkg
src
main
somepackage
vendor
And it seems to work

Golang import package error

go:5:2: cannot find package "github.com/googollee/go-socket.io" in any of:
/usr/local/go/src/github.com/googollee/go-socket.io (from $GOROOT)
/Users/YoungHoonKim/Documents/chat/src/github.com/googollee/go-socket.io (from $GOPATH)
I'm getting this error while trying to compile my chat.go file with LiteIDE. I'm following a guide to build a chatserver, so I don't know where this package should be. any help?
Double-check your actual go work directory with echo $GOPATH in your terminal.
This will be your starting point to identify if you have this package at all, for example you should be able to see this package doing cd $GOPATH/src/github.com/googollee/go-socket.io.
For more details on correct directory location (workspace in general) please check https://golang.org/doc/code.html

Go get not fetching all dependencies

I am using go 1.5.1 on Windows 8.1 64-bit. I do not have GO15VENDOREXPERIMENT set in my environment. I have the latest version of git and bazaar installed.
I am trying to get the gomniauth package:
go get github.com/stretchr/gomniauth
Even though the process completes without any error, a lot of dependencies aren't pulled in.
For example, when compiling my app (which depends on gomniauth), I get these errors:
..\github.com\stretchr\codecs\xml\simple_xml_codec.go:5:2: cannot find package "github.com/clbanning/x2j" in any of:
C:\Go\src\github.com\clbanning\x2j (from $GOROOT)
C:\work\src\github.com\clbanning\x2j (from $GOPATH)
..\github.com\stretchr\codecs\msgpack\msgpack_codec.go:6:2: cannot find package "github.com/ugorji/go/codec" in any of:
C:\Go\src\github.com\ugorji\go\codec (from $GOROOT)
C:\work\src\github.com\ugorji\go\codec (from $GOPATH)
..\github.com\stretchr\codecs\bson\bson_codec.go:5:2: cannot find package "labix.org/v2/mgo/bson" in any of:
C:\Go\src\labix.org\v2\mgo\bson (from $GOROOT)
C:\work\src\labix.org\v2\mgo\bson (from $GOPATH)
It seems to pull in the direct dependencies for gomniauth, but doesn't pull in the dependencies of the dependencies. I have gone and deleted the stretchr folder from my GOPATH/src as well as GOPATH/pkg, but after running go get many times, it is still not pulling in the any dependencies beyond the second level.
I am 100% confident there are no network issues on my end. I can access those github repos using my browser or curl.
Change directory to your project and then try go get ./...
E.g.:
cd C:\work\src\github.com\stretchr\gomniauth
go get ./...
Or just go get github.com/stretchr/gomniauth/... as Amit Kumar Gupta suggested
In my case I was missing the bzr package.
After adding it using dnf install bzr and running #RoninDev suggestion it worked as expected:
cd $GOPATH/src/github.com/stretchr/gomniauth
go get ./...

Resources