Unable to setup Gandalf Go - 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.

Related

main packages in go 1.18.1 built-in libraries

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).

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!

Golang issue in vs code while accessing private repo

I have a Golang project and the version I am using is 1.13. And my module is hosted in my private repo. And my repo starts with:
module <Private-Repo>-service
go 1.13
And there are some Repos that are from Github and go packages. I am using Golang's vs code package
Go Team at Google
I have my env like:
GOROOT="/usr/local/go"
GOPATH="/home/{User}/go"
GOPRIVATE=<Private-Repo-URL>
And my folder where I am copying my Repo is inside /home/{User}/go/src/
But I am unable to fix the issue and it is saying:
could not import github.com/golang/mock/gomock (cannot find package "github.com/golang/mock/gomock" in any of
/usr/local/go/src/github.com/golang/mock/gomock (from $GOROOT)
/home/{User}/go/src/github.com/golang/mock/gomock (from $GOPATH))compilerBrokenImport
So I need to fix this issue in the visual studio code.
Try first if the issue persists:
in command-line (go get github.com/golang/mock/gomock, in the root folder of your project, where go.mod/go.sum are)
after upgrading, if possible, to go 1.17.
Once a go build is working in command-line, you can switch back to VSCode, and confirm it is also fine there.
Instead of storing your code directly inside your $GOPATH, try to store it inside another directory namely github.com/{github-username}/.
From:
/home/{User}/go/src/
To:
/home/{User}/go/src/github.com/{github-username}/

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.

How to install an updated version of a Dart package?

When a new Dart package is published, how can I install the updated version?
The DartEditor calls pub get automatically when the file pubspec.yaml is updated.
You may call it manually (e.g. when you for example checked out a project from GitHub without modifying any file)
by using the context menu Pub Get in DartEditor on the file pubspec.yaml
by calling pub get on the command line in the package directory where the file pubspec.yaml is stored.
pub get downloads the package version noted in the file pubspec.lock (in the package root directory) or the most recent version that fulfills your version constraint (0.0.1 in your example could be any for 'most recent') if pubspec.lock doesn't exist. pub get/pub upgrade create the file pubspec.lock if it doesn't yet exist and save the versions of the downloaded packages it just downloaded.
Check for updated packages and download them using
context menu Pub Upgrade in DartEditor on the file pubspec.yaml
pub upgrade on the command line in the package directory where the file pubspec.yaml is stored.
pub upgrade downloads the most recent version that fulfills your version constraints and stores the downloaded version in the file pubspec.lock.
pub get/pub upgrade prefers stable releases (version numbers that don't contain a -) like 0.0.1 or 1.2.0+1 over pre-releases like 0.0.2-1 or 1.2.1-1 if any is available that fulfulls your version constraint.
If you want a pre-release you have to tighten the version constraint so that only the pre-release fulfills your constraints (like angular: '>=1.2.1')
pub upgrade may show an output like
analyzer 0.10.5 (9 newer versions available)
Which indicates that there are 9 prerelease builds available that are newer than the downloaded stable build.
The version constraint for your dependency needs to fulfill the version constraints of all your dependencies dependencies (E.g. if you add the dependencies observe and polymer where polymer depends on observe itself).
You can force pub get/pub upgrade to a version that violates your dependencies dependency by defining the dependency with a version constraint under dependencies_override: instead of dependencies: in pubspec.yaml.
You may also add dev_dependencies (e.g. unittest) which are only downloaded when they are defined in your package but ignored when they are only defined in one of your dependencies.
You see, this is an advanced topic even for seasoned Dart developers.
If you are a seasoned Dartisan, this question might seem so trivial to not be worth asking, but coming from a Java world (where my students and I are used to downloading .jars manually and then (sometimes) having to copy them over into our projects) it is a greenhorn question that is natural to ask. Here is the context: two days ago v0.9.5 of angular came out and so I made a mental note to upload the libraries in our local projects.
Well, it seems that all we need is an appropriately defined pubspec.yaml file, and the Dart pub package manager does the rest. In the Dart Editor, I guess that dependencies get updated on a project refresh or when it is (re-)built. In our projects we happened to have, e.g., a pubspec.yaml file like this:
name: angular_dart_demo
version: 0.0.1
dependencies:
angular: any
(as opposed to, say, angular: ">=0.9.0 <0.10.0") which allowed the Pub manager to go fetch the latest angular. Effortless. Nice.

Resources