main packages in go 1.18.1 built-in libraries - go

I am trying to upgrade my project's golang version from 1.15 to 1.18.1. I changed the version in go.mod and executed go mod tidy command.
Weird thing, I got following error in my main file which has a main function inside itself:
'main' collides with name declared in this package
It happens for net/http and syscall libraries:
net/http
Found several packages [http, main] in '/usr/local/go-1.18.1/src/net/http;/usr/local/go-1.18.1/src/net/http'
syscall
Found several packages [syscall, main] in '/usr/local/go-1.18.1/src/syscall;/usr/local/go-1.18.1/src/syscall'
As I checked the warning was correct and there were main packages in both libraries.
Should I use an alternative library or should I change the way I import them?
Edit 1:
This is an IDE error and I use Goland.

This was reported recently (Apr. 2022) (link in Chinese)
The translation of the relevant comment is:
The reason for the above error: Your Go language version has been upgraded, and the IDE version is too old to support it.
For example, in my case, Go was upgraded to 1.18, and Goland was not upgraded.
So make sure your IDE (GoLand or VSCode) is fully updated (with, for VSCode, the latest gopls).

Related

What happens when my go.mod version is newer than the golang version of the container image im using? [duplicate]

Given the following go.mod file:
module foo
go 1.12
require (
github.com/bar/baz v1.0.0
github.com/rat/cat v1.0.0
)
What does the go 1.12 indicate? Does it prevent compiling the foo module against any other version of Go? Or is it simply an indicator of the foo's recommended/required Go version? Is this a directive that we should update whenever a new version of go is released (every 6 months)?
It should be considered along the lines of a minimum required Go Version. If you build with the same or a higher version of Go, all should be fine as promised by the Go 1 compatibility promise. If you build with a lower version there will be an error message if the build fails:
The go directive in a go.mod file now indicates the version of the language used by the files within that module. It will be set to the current release (go 1.12) if no existing version is present. If the go directive for a module specifies a version newer than the toolchain in use, the go command will attempt to build the packages regardless, and will note the mismatch only if that build fails. Go 1.12 Release Notes

Can Jetbrains GoLand use both GoModule and GOPATH?

I'm working in fibrechannel project, and there are same level project(common) that fibrechannel depends on.
When I select Enable Go modules integration as below:
IDE tells me logger not found. (Note I'm using red rectangle to mark the reference and it's actually location under common folder)
After I unclick the Enable Go modules integration checkbox. (Note GOPATH looks like below)
IDE tells me "github.com/pkg/errors" not found.
the go.mod under fibrechannel looks like below:
module fibrechannel/src
go 1.12
require (
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.3.0
gopkg.in/iconv.v1 v1.1.1
gopkg.in/yaml.v2 v2.2.2
)
I'm a newbie in GO language, and I just want the IDE to resolve dependencies successfully.
I'm wondering if there's a way to make both GOPATH and GoModules work in Jetbrains GoLand. If not, is there a way to modify go.mod so that it can include GOPATH?
Finally, I managed to solve this issue.
B.T.W, since this is an old project maintained by many team members. I don't want to change its code structure, all I need is to read the content without any unknown reference in GoLand.
The solution is NOT to use go modules.
I unchecked the Enable Go modules integration so that only libraries in venders folder not found.
Then I manually added venders folder into GOPATH.
Now dependencies are all resolved!

How to find go package version?

I am not using go modules. Have a bunch of packages present in my company's toolchain (i.e. I didn't install the packages and thus can't check my bash history for package version).
So the packages are present in $TOOLCHAIN_PATH/go/src. Is there any way I can find the version of a particular package.
If it helps, I want to find out the package version of crypto/tls.
I am not using go modules
So you are doing it wrong. It's 2021, you must use modules. Use modules.
I want to find out the package version of crypto/tls
This is a package of the stdlib which is shipped with your compiler and it is "unversioned" as a package. Run go version to see the version of your compiler/stdlib combination as a whole.

Unable to setup Gandalf Go

I am trying to setup Gandalf but when I do go get github.com/JumboInteractiveLimited/Gandalf I'm getting error
package github.com/jmartin82/mmock/definition: cannot find package "github.com/jmartin82/mmock/definition" in any of:
/usr/local/go/src/github.com/jmartin82/mmock/definition (from $GOROOT)
<My_Go_Path>/src/github.com/jmartin82/mmock/definition (from $GOPATH)
I'm using testing file from
This reached me via a GitHub Issue however I thought it best to mention it here for clarity.
Gandalf utilizes go modules to pin dependency versions, go get will download the latest version of a dependency rather than the version a project actually supports where as something like go mod download will respect the go.mod file and fetch the correct version. The mmock project has changed its package structure making newer versions of it not backwards compatible.
I recommend getting antiquated with go modules as they seem to be the way forward now and have been enabled by default in newer versions of the go compiler. If I remember correctly you may already have support for it you just need to set the environment variable GO111MODULE=on when dealing with projects that have a go.mod file.

decoding dwarf section info at offset 0x0: too short

I am using JetBrains GoLand and I am trying to debug my go file and I am getting the following error:
decoding dwarf section info at offset 0x0: too short
I tried to find an answer here at StackOverflow but unfortunately, I didn't get any solution.
GoLand ships with a bundled version of Delve. Update to 2018.2.2 and it should work. If you need to do remote debugging, then you need to update your Delve installation on/for the target machine as well (make sure you compile it with Go 1.11).
Edit:
There are two more possible cases where this issue can appear:
the application was compiled with all the debugging flags turned off and the additional debugging information stripped
the application uses the standard library "plugin" package, which is known to cause an issue in the Go compiler. This will be fixed in Go 1.12.
I would like to share my experience here too as it may be helpful for community, I made it works by doing the following:
Update Goland to 18.3
Also, in case if you have Mac, you should run xcode-select --install
In case if you had delv already installed inside GOPATH/bin, remove it and re-install it again by following instructions here
For my Mac the problem is related to the dlv package as installed by Golang plugin.
Install delv and,
check the path of dlv as executed by IntelliJ (in the console).
Go to this directory
($HOME//Library/Application Support/IntelliJIdea2017.3/intellij-go/lib/dlv/mac)
and rename dlv to any other name. Get the right dlv executable by using
which dlv (/usr/local/Cellar/go/1.11.1/libexec/bin/dlv for my computer)
and add a symbolic link
(ln -s /usr/local/Cellar/go/1.11.1/libexec/bin/dlv dlv).
After hours of effort, I was able to find the issue. It was due to Golang Plugin which is deprecated and was not compatible with IntelliJ IDEA 2018.2.2 (Ultimate Edition).
I uninstalled the plugin and reinstall the IntelliJ.
Hope this also helps to above solutions.

Resources