VSCode go extension: could not import error [closed] - go

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm currently learning golang, I'm using windows
I've installed VSCode's Go extension.
When I hover over new package added by goimports in VSCode, I get the error
could not import io/ioutil (cannot find package "io/ioutil" in any of
C:\Users\<username>\go\src\io\ioutil (from $GOROOT)
C\src\io\ioutil (from $GOPATH)
\Users\<username>\go\src\io\ioutil (from $GOPATH))compiler
I have installed go in C:\Users\<username>\go. When I check the directory C:\Users\<username>\go\src\io\ioutil it exists(the ioutil.go file is present as well).
It's a package in go's standard library, yet it is not detected by the extension. I have to reload VSCode for it to work. Also when I compile the code using go build or go run command, the code compiles.

You should install Go somewhere else than C:\Users\<username>\go as that is also default GOPATH. Having GOPATH (a directory where your user modules are installed) in same place as GOROOT (a directory where Go itself is installed) will cause a lot of different problems and confuse many tools.
Either completely remove current installation and re-install Go somewhere else (recommended) or point your GOPATH somewhere else.

Related

goland on windows not recognizing imports and throw error [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 18 days ago.
Improve this question
i have enabled the go modules integration according to this docs .
https://www.jetbrains.com/help/go/create-a-project-with-go-modules-integration.html#enable-go-modules-in-a-project
but yet again as you can see in image below . goland keep throwing error on some code i have
as you can see in image i have that execlise package but it keep giving error . not only that i have some error on other files
That happens sometimes with IDEs, from my experience it may happen because of at least three reasons.
first: the differences between package versions in your go.sum, you should empty the go.sum and run go mod tidy command.
Second: the version you’re using is older or newer than what you’re expecting, so the package does not support these methods or didn’t include them. so you should set the exact version of the package. (I suggest you read the documentation of the package in this case)
Third: your IDE has got some problems with the caches. for solving this: you should click on file -> invalidate caches to rebuild your IDE caches.

GO no go.mod file exists in directory [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 months ago.
Improve this question
I'm starting with GO, and I want to create a virtualenv like in Python (to store import modules at the project directory itself), I read in GO's doc https://go.dev/doc/tutorial/workspaces and understand that GO's Create the workspace is what i'm doing need. But when I do, it doesn't work. Like in the attached image, after "go mod init .../hello_go" complete, then "go work init ./hello_go" and something wrong.
I don't understand what is the problem?
The problem is that the go.work file is supposed to be at the root of your project and point to subdirectories containing a go.mod file.
The error is telling you that there is no directory ./hello_go containing a go.mod file. This is correct because you have initialized your module also at the root level.
If you have only a single module, you don't need to create a workspace. You can create your module at root level like you did, and then use go mod to manage your dependencies for that particular module.

How to compile a go project with multiple packages and files to get an executable file in linux platform? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
For example, I have a project with following structure:
hello
- packageA
- subDirA
- Afile1.go
- Afile2.go
- packageB
- Bfile.go
- Bfile2.go
- packageC
- main.go
- subdirC
- xx.json
- packageD
-xx.go
How can I build them and get an executable file xxx on Linux platform, so that I can directly call them by ./xxxx?
Short answer: go build
You can run go help build to learn more on how to use it. For example, it's possible that you'll want to provide a specific path to go build, or build with ./.... It depends on the exact layout of your project.
I strongly recommend you to read some official Go documentation pages first:
Getting started with Go
How to write Go code
Work through the examples in these pages (and the other pages they lead to); this will answer most of your questions. The second link, in particular, talks about properly using go build and go install to build your projects.

Find out number of installs of a package [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 2 years ago.
Improve this question
Let's say that I want to figure out how many programmers import https://github.com/golang-migrate/migrate, similar to how I can figure it out for npm package on this website.
I know that you can guess the popularity of a package from the number of github stars, commmits etc, but I think installs count gives the most accurate picture of how popular a package is. Go package loading method is different from npm, so I wonder if it's even possible to get such intel?
Thanks in advance for your time!
Given the go tool doesn't collect/send this metric, no.
There is a different metric tracked on pkg.go.dev that shows how many other packages import the package in question.
When you open a package page (e.g. migrate) on the same line next to the version, license there is also Imported By with number. You can see detailed list of importers (only those known to pkg.go.dev site) on page it links to.
While this is not same thing npm does it can give you a rough idea of package popularity.
https://godoc.org/ shows the number of package imports right under the package name on searching for the package.
For e.g., when you search for the fmt package, it shows it has been imported 827695 times as of 23 January, 2021. This is close to the functionality of the npm site that you have referenced.

Where is the composer.json file located for a Zend Framework 3 application? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I'm looking at a Zend Framework 3 application on a server, and I don't see any composer.json file in the root.
I'm trying to download the entire application and add it to GitHub, but I don't want to download the vendor files (which I assume I can just download after running composer) but I'm not seeing any composer.json file to know what packages are external libraries, etc...
Does anybody know where the composer file is or what is the right way to go about this?
This is what's on the root directory
Long story short: it was deleted.
Short story long: you should recreate the composer.json file from the vendor/composer/installed.json file. See this thread for more information.
You shouldn't just download the original composer.json from the repo as #Alain Pomirol suggests, because there may be additional packages installed.
Also, temporarily include the vendor directory in the git repository. When you're ready with the composer.json file install dependencies again and check via git diff if that person didn't make any forbidden modifications to the vendor files. I've seen that so many times before…
A normally installed application must present a composer.json file in the root. You can find the model here : https://github.com/zendframework/ZendSkeletonApplication

Resources