I cloned code here: https://github.com/kkdai/line-login-go.
I deployed on heroku and ran successfully. But I get: cannot find package on VSCode
Normally, if I put the project in the src directory, and set GOPATH, it will not report an error.
But this project doesn't follow that structure, packages are in the vendor/ directory.
What do I have to do to handle the error?
You could try and use/add go modules to your cloned project (with Go 1.11+, and GO111MODULE=on set):
go mod init github.com/kkdai/line-login-go
go mod vendor
Then you should have all missing dependencies added to your vendor folder.
And you would not even need GOPATH anymore.
As seen in kardianos/govendor/issue 424, go mod should recognize vendor/vendor.json and import the right references previously declared and managed by govendor.
Related
i have a Revel project and i can't start it because everytime i run go mod tidy, it looks like finding module but it's not putting the found module in go.sum
here's my go env
GOENV = C:\Users\mycomp\AppData\Roaming\go\env
GOMOD = C:\Program Files\Go\src\myproject\go.mod
GOPATH = C:\Users\micha\go
go version
go version go1.18.3 windows/amd64
revel version
Revel executing: displays the Revel Framework and Go version
Revel Framework : Unknown (1.1.0 remote master branch)
Revel Cmd : 1.1.2 (1.1.2 remote master branch)
Revel Modules : Unknown (1.1.0 remote master branch)
go mod tidy
go: finding module for package github.com/PaesslerAG/jsonpath
go: finding module for package github.com/tdewolff/test
go: finding module for package github.com/PaesslerAG/gval
go: found github.com/tdewolff/test in github.com/tdewolff/test v1.0.7
go: found github.com/PaesslerAG/gval in github.com/PaesslerAG/gval v1.2.0
go: found github.com/PaesslerAG/jsonpath in github.com/PaesslerAG/jsonpath v0.1.1
go mod init myproject seem working because it create go.mod but it's just odd because it only creates this line, usually it creates a lot of modules i need
module myproject
go 1.18
then when i type go mod tidy, it creates empty go.sum. What do i miss ?
Cause the problem is too complex to reproduce online, i started to debug and reinstall my Go from scractch, between solving a bug where my program can't run i tried several things that might be useful
after Go 1.15 or 1.17 , my Go project can't run properly, so i put it in C:\Program Files\Go\src\<project_name>
The problem that i have is in GOPATH (usually in C:\Users\<comp_name>\go) don't have src folder, that makes it found downloaded module but can't seem to put it in go.mod inside my project
So in the end i reinstall all my Go and Revel. Here's how to delete all your associated Go to really really delete all your files
Delete Go Folder in C:\Program Files\Go\
Delete go folder in C:\Users\<comp_name>\go
View all hidden files and delete folder go-build in C:\Users\<comp_name>\AppData\Local
View all hidden files and delete folder go if any in C:\Users\micha\AppData\Roaming
I am trying to download, make some tweaks and build a golang project from GitHub. The project's instructions are:
go get github.com/<vendor>/<projectName>
cd src/github.com/<vendor>/<projectName>
go build .
That used to work in the past — before enabling Go Modules.
Now I have GO111MODULE=on (go version go1.15.4 linux/amd64). When running the first command, go downloads the project as a module and all its dependencies.
But then there is no src/github.com/<vendor>/<projectName> folder anymore. Moreover, the is no folder named <projectName> anywhere in the system.
Instead, there is folder pkg/mod/github.com/<vendor> which contains the project folder with weird symbols in its name (exclamation marks etc.) and version identifiers.
How do I get the project folder available for making tweaks and builds?
As pointed by #Volker, good old git clone should be used.
It turns out that it should be used instead of go get github.com/<vendor>/<projectName> (no idea why the project vendor recommends that):
git clone git://github.com/<vendor>/<projectName>
cd <projectName>
go get ./...
# do tweaks here
go build .
If your goal is tweaks, the easiest way it use to use go mod vendor.
https://golang.org/ref/mod#go-mod-vendor
The go mod vendor command constructs a directory named vendor in the main module's root directory that contains copies of all packages needed to support builds and tests of packages in the main module
My golang version is go1.10.2 linux/amd64. I can build and run my go project(under gopath/src) without any problem but I cannot see vendor directory under my project folder. I would like to know if the vendor folder is a hidden directory? What are the possible reasons the vendor folder is not generated?
Vendor directory is used as an alternative to GOPATH when resolving dependencies. A dependency is first looked up in /vendor then in GOPATH then in GOROOT.
If you go get all your dependencies they'll be in GOPATH/src instead of /vendor.
To start adding project specific dependencies to vendor dir you need to use a dependency manager such as glide or dep or manually copy everything to /vendor.
This SO answer goes into more detail on using vendor dir in Go - https://stackoverflow.com/a/37238226/1589165
Everything I read about the vendor directory gives me the understanding that if I have a directory:
$GOPATH/src/vendor
And put my dependencies in there (I am using godeps), when doing go run, go should check in that directory first.
If I run my code in a Docker image I have, this works fine. However now that I try to run the same code on my Windows machine, go simply ignores the vendor/ directory, and fails to find the dependencies.
What am I doing wrong?
main.go:7:2: cannot find package "gopkg.in/alecthomas/kingpin.v2" in any of:
C:\Go\src\gopkg.in\alecthomas\kingpin.v2 (from $GOROOT)
C:\Users\js\dev\my_project\rest\src\gopkg.in\alecthomas\kingpin.v2 (from $GOPATH)
C:\Users\js\dev\go\src\gopkg.in\alecthomas\kingpin.v2
Is the output when I try to do:
go run main.go
A directory vendor/ exists in this directory.
go version go1.7 windows/amd64
The exact commands I run (in windows cmd.exe)
> cd C:\Users\js\dev\my_project\rest\
> set GOPATH=C:\Users\js\dev\my_project\rest\;c:\Users\js\dev\go
> cd src
> dir
...
2016-09-01 23:20 2 923 main.go
...
2016-09-03 01:27 <DIR> vendor
> go run main.go
The reason this did not work is because you are not supposed to put any code directly into the $GOPATH/src/ directory.
The solution is to put your project into a sub-directory like so:
$GOPATH/src/app/*.go
Seems your GOPATH is incorrect?
The GOPATH should specify the location of your workspace i.e. directory containing src, pkg and bin directories at its root.
Try doing
set GOPATH=C:\Users\js\dev\my_project\rest\;c:\Users\js\dev\go
More details at: https://golang.org/doc/code.html
The first thing to understand is that godep save is simply copying dependencies from your $GOPATH to a vendor directory inside your project.
You will have to go get your dependencies first. After you have them in $GOPATH, you can do a godep save to copy the current version to your project, and be assured that even if the version in $GOPATH changes, you will have a fixed version in your project until you explicitly change it via godep.
So, if I have a $GOPATH of /home/me/go_workspace, and a project called $GOPATH/src/github.com/project_x with a dependency of github.com/you/xyz, then I would do go get github.com/you/xyz, and godep save from within my project directory. This would create a vendor folder with the dependency at its current commit inside.
I have a project which is built in Node.js/Express.js. I want to start to rewrite this to go/iris framework. I don't want to re-factor everything into my $GOPATH and I want to keep it together my express / go / docker files for this project.
I tried to clone iris framework's git repo into a ./vendor subfolder, but using import "github.com/kataras/iris" importing nothing.
Is there a package manager which is
copying and installing packages and all of it's dependencies in my-project/vendor folder outside $GOPATH
it can update these import packages
go run/build/install outside $GOPATH
there's now any new files in $GOPATH src/pkg/bin folder when I working on a project, except this package manager
I can define dependency packages for a project like package.json file for node.js
Is there a go package manager like that?
Edit:
Running this with go command is not required.
Not possible with the current go tooling, but looks like we might get it in go 1.12 or bit later.
Proposal accepted:
cmd/go: modify the Go toolchain to work without GOPATH