Problems with dependencies after setting up go dep - go

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

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

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

Golang 1.6 Cannot find packages in vendor folder

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.

How do I install requirements in Go? "cannot find package"

I'm new to Go and I'm trying to set up a Go project with minimal documentation: https://github.com/alphagov/metadata-api
I've cloned it, but when I try go build I get the following warnings:
main.go:8:2: cannot find package "github.com/Sirupsen/logrus" in any of:
/usr/local/Cellar/go/1.3.3/libexec/src/pkg/github.com/Sirupsen/logrus (from $GOROOT)
/Users/me/go/src/github.com/Sirupsen/logrus (from $GOPATH)
main.go:14:2: cannot find package "github.com/alphagov/metadata-api/content_api" in any of:
/usr/local/Cellar/go/1.3.3/libexec/src/pkg/github.com/alphagov/metadata-api/content_api (from $GOROOT)
/Users/me/go/src/github.com/alphagov/metadata-api/content_api (from $GOPATH)
I'm guessing this is because I haven't installed the Go equivalent of requirements?
My GOPATH is set:
metadata-api$ echo $GOPATH
/Users/me/go
And the Go executable is in
metadata-ape$ echo $PATH
....:/Users/me/go/bin
What do I need to do to help Go find these packages?
You should install package first:
try
$ go get github.com/Sirupsen/logrus
and check you $GOPATH dir
This project use gom as the package manager,
Make sure you have installed gom
or try this command
$ gom install
I think your $GOPATH and $PATH settings are incorrect, the $GOPATH environment variable specifies the location of your workspace, these are my path settings:
export GOROOT=$HOME/bin/go
export GOBIN=$GOROOT/bin
export GOPATH=$HOME/golang
export PATH=$PATH:$GOBIN
I had similar issue and
export GO111MODULE=on
helped.
When you need your code to do something that might have been implemented by someone else (in Github or a package somewhere else), You should initialize a go mod file inside of your folder.)
For the purposes of this example, I'll just use example.com/module.
go mod init example.com/module
Add new module requirements and sums:
go mod tidy
Run your program:
go run .
For more details, see https://golang.org/doc/tutorial/getting-started.
Was able to fix the similar issue in Go 1.13.7 by typing:
export GOPATH=~/go
go get github.com/profile/repository
(e.g. github.com/Sirupsen/logrus)
"...Starting in Go 1.13, module mode will be the default for all development..."
"...When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin)..."

Build and install golang project with some internal packages

I have following golang project structure:
- go-projects
- src
- github.com
- user
- my-project
- pack
- pack.go
- main.go
my GOPATH is:
export GOPATH=/home/user/go-projects
I'm trying to call functions from pack package in main.go file and trying to build this project with:
cd my-project
go build && go-install
There is no any output, and also there is no bin directory anywhere. What i did wrong?
UPD This problem was solved. accidently missunderstood file content of main.go and pack.go. But now there is another problem.
How to build correctly this program. When i'm trying to execute go build in /home/user/go-projects/src/github.com/user/my-project i'm getting following erros:
main.go:4:8: cannot find package "github.com/user/pack" in any of:
/home/user/Downloads/go/src/pkg/github.com/user/pack (from $GOROOT)
/home/user/go-projects/src/github.com/user/pack (from $GOPATH)
Thank you
While it may be convenient to let the tools infer the package from the current working directory, it doesn't work for much more than a simple main package. Get used to referencing packages by their full import path, and you'll save yourself other problems down the line.
go install github.com/user/pack
It goes into $GOPATH/bin/my-project, if you wanna test it right away just use go run main.go

Resources