Go plugin - "plugin was built with a different version of package" - go

I have an application that loads plugins on startup (daemon). In a subpackage (daemon/interfaces), I have a few interfaces that plugins for this program should use.
This means that the main program also gets imported by the plugin.
I am using Go modules (for both the main program and the plugin) to fix the versions, and I can see in go.mod that it is using the latest version of the main program for the plugin.
I can build them both fine, but when I load the plugin it gives me an error saying
panic: plugin.Open("plugins/my-plugin"): plugin was built with a different version of package daemon/interfaces
I am using Go 1.12.7 to build both of the packages.

I fixed this by adding a replace statement to my plugin go.mod file
module github.com/user/plugin
go 1.12
require (
github.com/user/daemon v1.1.1
)
replace github.com/user/daemon v1.1.1 => ../local/path/to/daemon/
It also helps when you are building the project from outside of the directory where the source code is in by using the full name of the project (go build github.com/user/project/)
There is a related Github issue on the Golang repository that you can find here

Apparently, the issue is still open. The issue opener presented the workaround, which I was able to use. Please look at the history lines below for details.
git clone https://github.com/zimnx/central.git
git clone https://github.com/zimnx/plugins.git
cd central/
go clean -modcache
git checkout v1.0.0
go install -a
cd ../plugins/
rm go.mod
go mod init github.com/zimnx/plugins
echo '' >> go.mod
echo 'replace github.com/zimnx/central => ../central' >> go.mod
go build -buildmode=plugin -o plugin.so
central plugin.so
Works for me. Mistery still... :) The output has been saved for the most curious.

Related

Golangļ¼šmodule declares its path as: bou.ke/monkey, but was required as: github.com/bouk/monkey [duplicate]

I am working on a go project, which has a dependency on original-project. I now want to change the behavior in this project by modifying original-project. So I cloned github.com/y/original-project to github.com/x/my-version and replaced all occurrence of github.com/y/original-project with github.com/x/my-version (including in mod.go).
But I keep getting this error:
go: github.com/x/my-version#v0.5.2: parsing go.mod:
module declares its path as: github.com/y/original-project
but was required as: github.com/x/my-version
Even when I run go get -u -v -f all or github.com/x/my-version
What could I be doing wrong?
I think the problem comes from the fact that the go.mod of your cloned version of original-project still says module github.com/y/original-project. You should use the go.mod replace directive. It is meant for cases like yours exactly.
replace github.com/y/original-project => /path/to/x/my-version
I had similar issue. I ended up removing the go.mod file in the project I was trying to import and running go mod init ... again. It fixed it.
Also, run go clean -modcache where you are importing.
Then try to go get ... your package.
I'm currently developing a Go package and had this issue. I initially used the module <package-name> syntax at the top of my go.mod file. Since the module wasn't downloading correctly, I switched the syntax to be module github.com/<user>/<package-name>. Unfortunately, my system was still stuck on the old download cache, even after I manually deleted the dependencies.
To fix the issue, I created a new release tag on GitHub for the project (v0.0.1-beta), and now it downloads fine. go get stores modules with the version tag, so this bypassed the issue.
The trick is to update the go mod cache.
So after making the required changes in go.mod (i.e. github.com/X/Z => github.com/Y/Z), you'll then need to pull down the latest version which will update your local go mod cache.
i.e. go get github.com/Y/Z#fd02212
and then the error message will go.
Use the go mod edit -replace command.
Example 1:
go mod edit -replace github.com/y/original-project=github.com/x/my-version#v0.5.2
Example 2:
go mod edit -replace github.com/codahale/hdrhistogram=github.com/HdrHistogram/hdrhistogram-go#v0.9.0
From: https://github.com/HdrHistogram/hdrhistogram-go
The only way i found to fix this is try to find all occurrences of the old (and new, maybe) dependency and remove it manually
find ~/go | grep original-project
rm -rf ~/go/pkg/mod/cache/download/github.com/y/original-project
rm -rf ~/go/pkg/mod/cache/download/github.com/x/my-version
rm -rf ~/go/pkg/mod/github.com/y/original-project*
rm -rf ~/go/pkg/mod/github.com/x/my-version*
rm -rf ~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/y/original-project*
rm -rf ~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/x/my-version*
Then go get again
In my case, I didn't want to just fix on local, but be sure it worked for everyone.
After changing values in go.mod (it was better to delete the go.mod and go.sum files then run
go mod init github.com/organization/new-package-name
go mod tidy
go get github.com/organization/new-package-name
Above didn't really solve the problem for me, nor did go clean -modcache.
What worked for me instead was deleting then recreating the tags on the newly forked project. (suggestion: Delete all tags from a Git repository)
Then create a new tag.
git tag v1.0.0 -m "new version"
git push origin v1.0.0
After this, you can just install via
go get github.com/organization/new-package-name#latest
OR
go get github.com/organization/new-package-name#v1.0.0
delete the go.mod and go.sum
go clean -modcache && go init
It worked for me
In my case, I edited my go.mod and added:
require github.com/anyuser/anyrepo **latest**
Then, in the terminal, entered:
go mod download
This worked for me:
Remove go.mod file from the directory
Run go clean -modcache
Run go get
I had the same issue with the package name, after searching a lot I found golang cache coming from golang proxy server "don't know how" but cache store on my mac cleaned by running go clean -modcache but when i use go mod download or go mod tidy it always pick the wrong version package.
after rewriting GOPROXY variable to GOPROXY="direct" everything starts working.
go env -w GOPROXY="direct"
If it starts working you can revert your GOPROXY settings and using direct will show the module downloading.
If you using Goland then make sure you have enabled Go Module Integration in settings for Autocomplete indirect modules.
What worked for me was
Changing module github.com/otherperson/therepo -> module github.com/me/therepo in the go.mod
then running
go get github.com/myfork#latest_commit_hash
I just did this and it worked.
go get -u "github.com/org/package#latest"
Actually I had the same error, I'm importing a private repo of mine from Github and the problem was that the name of the package ( first line in go.mod ) not the same name as the repo url. So we need to make sure that they are the same.
Error:
Github repo url: github.com/Mansouri147/private-repo
First line go.mod: module mansouri147/different-name
Success:
Github repo url: github.com/Mansouri147/private-repo
First line go.mod: module github.com/Mansouri147/private-repo
i just input go clean -modcache and input go mod tidy, then solve.

How to fix parsing go.mod module declares its path as "github.com/xx" but was required as "git-codecommit.cn-northwest-1.amazonaws.com.cn" [duplicate]

I am working on a go project, which has a dependency on original-project. I now want to change the behavior in this project by modifying original-project. So I cloned github.com/y/original-project to github.com/x/my-version and replaced all occurrence of github.com/y/original-project with github.com/x/my-version (including in mod.go).
But I keep getting this error:
go: github.com/x/my-version#v0.5.2: parsing go.mod:
module declares its path as: github.com/y/original-project
but was required as: github.com/x/my-version
Even when I run go get -u -v -f all or github.com/x/my-version
What could I be doing wrong?
I think the problem comes from the fact that the go.mod of your cloned version of original-project still says module github.com/y/original-project. You should use the go.mod replace directive. It is meant for cases like yours exactly.
replace github.com/y/original-project => /path/to/x/my-version
I had similar issue. I ended up removing the go.mod file in the project I was trying to import and running go mod init ... again. It fixed it.
Also, run go clean -modcache where you are importing.
Then try to go get ... your package.
I'm currently developing a Go package and had this issue. I initially used the module <package-name> syntax at the top of my go.mod file. Since the module wasn't downloading correctly, I switched the syntax to be module github.com/<user>/<package-name>. Unfortunately, my system was still stuck on the old download cache, even after I manually deleted the dependencies.
To fix the issue, I created a new release tag on GitHub for the project (v0.0.1-beta), and now it downloads fine. go get stores modules with the version tag, so this bypassed the issue.
The trick is to update the go mod cache.
So after making the required changes in go.mod (i.e. github.com/X/Z => github.com/Y/Z), you'll then need to pull down the latest version which will update your local go mod cache.
i.e. go get github.com/Y/Z#fd02212
and then the error message will go.
Use the go mod edit -replace command.
Example 1:
go mod edit -replace github.com/y/original-project=github.com/x/my-version#v0.5.2
Example 2:
go mod edit -replace github.com/codahale/hdrhistogram=github.com/HdrHistogram/hdrhistogram-go#v0.9.0
From: https://github.com/HdrHistogram/hdrhistogram-go
The only way i found to fix this is try to find all occurrences of the old (and new, maybe) dependency and remove it manually
find ~/go | grep original-project
rm -rf ~/go/pkg/mod/cache/download/github.com/y/original-project
rm -rf ~/go/pkg/mod/cache/download/github.com/x/my-version
rm -rf ~/go/pkg/mod/github.com/y/original-project*
rm -rf ~/go/pkg/mod/github.com/x/my-version*
rm -rf ~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/y/original-project*
rm -rf ~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/x/my-version*
Then go get again
In my case, I didn't want to just fix on local, but be sure it worked for everyone.
After changing values in go.mod (it was better to delete the go.mod and go.sum files then run
go mod init github.com/organization/new-package-name
go mod tidy
go get github.com/organization/new-package-name
Above didn't really solve the problem for me, nor did go clean -modcache.
What worked for me instead was deleting then recreating the tags on the newly forked project. (suggestion: Delete all tags from a Git repository)
Then create a new tag.
git tag v1.0.0 -m "new version"
git push origin v1.0.0
After this, you can just install via
go get github.com/organization/new-package-name#latest
OR
go get github.com/organization/new-package-name#v1.0.0
delete the go.mod and go.sum
go clean -modcache && go init
It worked for me
In my case, I edited my go.mod and added:
require github.com/anyuser/anyrepo **latest**
Then, in the terminal, entered:
go mod download
This worked for me:
Remove go.mod file from the directory
Run go clean -modcache
Run go get
I had the same issue with the package name, after searching a lot I found golang cache coming from golang proxy server "don't know how" but cache store on my mac cleaned by running go clean -modcache but when i use go mod download or go mod tidy it always pick the wrong version package.
after rewriting GOPROXY variable to GOPROXY="direct" everything starts working.
go env -w GOPROXY="direct"
If it starts working you can revert your GOPROXY settings and using direct will show the module downloading.
If you using Goland then make sure you have enabled Go Module Integration in settings for Autocomplete indirect modules.
What worked for me was
Changing module github.com/otherperson/therepo -> module github.com/me/therepo in the go.mod
then running
go get github.com/myfork#latest_commit_hash
I just did this and it worked.
go get -u "github.com/org/package#latest"
Actually I had the same error, I'm importing a private repo of mine from Github and the problem was that the name of the package ( first line in go.mod ) not the same name as the repo url. So we need to make sure that they are the same.
Error:
Github repo url: github.com/Mansouri147/private-repo
First line go.mod: module mansouri147/different-name
Success:
Github repo url: github.com/Mansouri147/private-repo
First line go.mod: module github.com/Mansouri147/private-repo
i just input go clean -modcache and input go mod tidy, then solve.

go build: no Go files in /msfs2020-go-master

Im trying to rebuild a golang github repository to apply some minor changes.
The go application Im trying to modify is the following https://github.com/lian/msfs2020-go
Please use the provided github link to inspect the file tree.
I used the master branch and extracted it to /user/Documents/msfs2020-go-master
If I call go build from /user/Documents/msfs2020-go-master the output equals: no Go files in /user/Documents/msfs2020-go-master
I tried deleting the go.mod and recreating it with go mod init github.com/lian/msfs2020-go followed with a go mod tidy
but still no Go files in /user/Documents/msfs2020-go-master
Here the current go.mod
module github.com/lian/msfs2020-go
go 1.16
require github.com/gorilla/websocket v1.4.2
And here the go.sum
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
The master was build with 1.14 and Im using 1.16 golang.
All my test go applications/modules run/build/install fine at a "Hello World" developing level.
What did I do wrong? I gladly accept any input and will provide additional information's if requested.
The command go build builds the package in the current working directory. The command reports an error because there is not a package at the root of the repository.
Fix by building the package containing the command. Any of the following will work from the root of the repository:
go build ./vfrmap
or
cd vrfrmap
go build
or
go build github.com/lian/msfs2020-go/vfrmap
See also the file build-vfrmap.sh.

How to fix parsing go.mod module declares its path as "x" but was required as "y"

I am working on a go project, which has a dependency on original-project. I now want to change the behavior in this project by modifying original-project. So I cloned github.com/y/original-project to github.com/x/my-version and replaced all occurrence of github.com/y/original-project with github.com/x/my-version (including in mod.go).
But I keep getting this error:
go: github.com/x/my-version#v0.5.2: parsing go.mod:
module declares its path as: github.com/y/original-project
but was required as: github.com/x/my-version
Even when I run go get -u -v -f all or github.com/x/my-version
What could I be doing wrong?
I think the problem comes from the fact that the go.mod of your cloned version of original-project still says module github.com/y/original-project. You should use the go.mod replace directive. It is meant for cases like yours exactly.
replace github.com/y/original-project => /path/to/x/my-version
I had similar issue. I ended up removing the go.mod file in the project I was trying to import and running go mod init ... again. It fixed it.
Also, run go clean -modcache where you are importing.
Then try to go get ... your package.
I'm currently developing a Go package and had this issue. I initially used the module <package-name> syntax at the top of my go.mod file. Since the module wasn't downloading correctly, I switched the syntax to be module github.com/<user>/<package-name>. Unfortunately, my system was still stuck on the old download cache, even after I manually deleted the dependencies.
To fix the issue, I created a new release tag on GitHub for the project (v0.0.1-beta), and now it downloads fine. go get stores modules with the version tag, so this bypassed the issue.
The trick is to update the go mod cache.
So after making the required changes in go.mod (i.e. github.com/X/Z => github.com/Y/Z), you'll then need to pull down the latest version which will update your local go mod cache.
i.e. go get github.com/Y/Z#fd02212
and then the error message will go.
Use the go mod edit -replace command.
Example 1:
go mod edit -replace github.com/y/original-project=github.com/x/my-version#v0.5.2
Example 2:
go mod edit -replace github.com/codahale/hdrhistogram=github.com/HdrHistogram/hdrhistogram-go#v0.9.0
From: https://github.com/HdrHistogram/hdrhistogram-go
The only way i found to fix this is try to find all occurrences of the old (and new, maybe) dependency and remove it manually
find ~/go | grep original-project
rm -rf ~/go/pkg/mod/cache/download/github.com/y/original-project
rm -rf ~/go/pkg/mod/cache/download/github.com/x/my-version
rm -rf ~/go/pkg/mod/github.com/y/original-project*
rm -rf ~/go/pkg/mod/github.com/x/my-version*
rm -rf ~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/y/original-project*
rm -rf ~/go/pkg/mod/cache/download/sumdb/sum.golang.org/lookup/github.com/x/my-version*
Then go get again
In my case, I didn't want to just fix on local, but be sure it worked for everyone.
After changing values in go.mod (it was better to delete the go.mod and go.sum files then run
go mod init github.com/organization/new-package-name
go mod tidy
go get github.com/organization/new-package-name
Above didn't really solve the problem for me, nor did go clean -modcache.
What worked for me instead was deleting then recreating the tags on the newly forked project. (suggestion: Delete all tags from a Git repository)
Then create a new tag.
git tag v1.0.0 -m "new version"
git push origin v1.0.0
After this, you can just install via
go get github.com/organization/new-package-name#latest
OR
go get github.com/organization/new-package-name#v1.0.0
delete the go.mod and go.sum
go clean -modcache && go init
It worked for me
In my case, I edited my go.mod and added:
require github.com/anyuser/anyrepo **latest**
Then, in the terminal, entered:
go mod download
This worked for me:
Remove go.mod file from the directory
Run go clean -modcache
Run go get
I had the same issue with the package name, after searching a lot I found golang cache coming from golang proxy server "don't know how" but cache store on my mac cleaned by running go clean -modcache but when i use go mod download or go mod tidy it always pick the wrong version package.
after rewriting GOPROXY variable to GOPROXY="direct" everything starts working.
go env -w GOPROXY="direct"
If it starts working you can revert your GOPROXY settings and using direct will show the module downloading.
If you using Goland then make sure you have enabled Go Module Integration in settings for Autocomplete indirect modules.
What worked for me was
Changing module github.com/otherperson/therepo -> module github.com/me/therepo in the go.mod
then running
go get github.com/myfork#latest_commit_hash
I just did this and it worked.
go get -u "github.com/org/package#latest"
Actually I had the same error, I'm importing a private repo of mine from Github and the problem was that the name of the package ( first line in go.mod ) not the same name as the repo url. So we need to make sure that they are the same.
Error:
Github repo url: github.com/Mansouri147/private-repo
First line go.mod: module mansouri147/different-name
Success:
Github repo url: github.com/Mansouri147/private-repo
First line go.mod: module github.com/Mansouri147/private-repo
i just input go clean -modcache and input go mod tidy, then solve.

How do I import a specific version of a package using go get?

coming from a Node environment I used to install a specific version of a vendor lib into the project folder (node_modules) by telling npm to install that version of that lib from the package.json or even directly from the console, like so:
$ npm install express#4.0.0
Then I used to import that version of that package in my project just with:
var express = require('express');
Now, I want to do the same thing with go. How can I do that?
Is it possible to install a specific version of a package? If so, using a centralized $GOPATH, how can I import one version instead of another?
I would do something like this:
$ go get github.com/wilk/uuid#0.0.1
$ go get github.com/wilk/uuid#0.0.2
But then, how can I make a difference during the import?
Go 1.11 will have a feature called go modules and you can simply add a dependency with a version. Follow these steps:
go mod init .
go mod edit -require github.com/wilk/uuid#0.0.1
go get -v -t ./...
go build
go install
Here's more info on that topic - https://github.com/golang/go/wiki/Modules
Really surprised nobody has mentioned gopkg.in.
gopkg.in is a service that provides a wrapper (redirect) that lets you express versions as repo urls, without actually creating repos. E.g. gopkg.in/yaml.v1 vs gopkg.in/yaml.v2, even though they both live at https://github.com/go-yaml/yaml
gopkg.in/yaml.v1 redirects to https://github.com/go-yaml/yaml/tree/v1
gopkg.in/yaml.v2 redirects to https://github.com/go-yaml/yaml/tree/v2
This isn't perfect if the author is not following proper versioning practices (by incrementing the version number when breaking backwards compatibility), but it does work with branches and tags.
A little cheat sheet on module queries.
To check all existing versions: e.g. go list -m -versions github.com/gorilla/mux
Specific version #v1.2.8
Specific commit #c783230
Specific branch #master
Version prefix #v2
Comparison #>=2.1.5
Latest #latest
E.g. go get github.com/gorilla/mux#v1.7.4
You can use git checkout to get an specific version and build your program using this version.
Example:
export GOPATH=~/
go get github.com/whateveruser/whateverrepo
cd ~/src/github.com/whateveruser/whateverrepo
git tag -l
# supose tag v0.0.2 is correct version
git checkout tags/v0.0.2
go run whateverpackage/main.go
Glide is a really elegant package management for Go especially if you come from Node's npm or Rust's cargo.
It behaves closely to Godep's new vendor feature in 1.6 but is way more easier. Your dependencies and versions are "locked" inside your projectdir/vendor directory without relying on GOPATH.
Install with brew (OS X)
$ brew install glide
Init the glide.yaml file (akin to package.json). This also grabs the existing imported packages in your project from GOPATH and copy then to the project's vendor/ directory.
$ glide init
Get new packages
$ glide get vcs/namespace/package
Update and lock the packages' versions. This creates glide.lock file in your project directory to lock the versions.
$ glide up
I tried glide and been happily using it for my current project.
Nowadays you can just use go get for it. You can fetch your dependency by the version tag, branch or even the commit.
go get github.com/someone/some_module#master
go get github.com/someone/some_module#v1.1.0
go get github.com/someone/some_module#commit_hash
more details here - How to point Go module dependency in go.mod to a latest commit in a repo?
Go get will also install the binary, like it says in the documentation -
Get downloads the packages named by the import paths, along with their dependencies. It then installs the named packages, like 'go install'.
(from https://golang.org/cmd/go/)
Update 18-11-23: From Go 1.11 mod is official experiment. Please see #krish answer.
Update 19-01-01: From Go 1.12 mod is still official experiment.
Starting in Go 1.13, module mode will be the default for all development.
Update 19-10-17: From Go 1.13 mod is official package manager.
https://blog.golang.org/using-go-modules
Old answer:
You can set version by offical dep
dep ensure --add github.com/gorilla/websocket#1.2.0
From Go 1.5 there's the "vendor experiment" that helps you manage dependencies. As of Go 1.6 this is no longer an experiment. Theres also some other options on the Go wiki..
Edit: as mentioned in this answer gopkg.in is a good option for pinning github-depdencies pre-1.5.
dep is the official experiment for dependency management for Go language. It requires Go 1.8 or newer to compile.
To start managing dependencies using dep, run the following command from your project's root directory:
dep init
After execution two files will be generated: Gopkg.toml ("manifest"), Gopkg.lock and necessary packages will be downloaded into vendor directory.
Let's assume that you have the project which uses github.com/gorilla/websocket package. dep will generate following files:
Gopkg.toml
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
[[constraint]]
name = "github.com/gorilla/websocket"
version = "1.2.0"
Gopkg.lock
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/gorilla/websocket"
packages = ["."]
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
version = "v1.2.0"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "941e8dbe52e16e8a7dff4068b7ba53ae69a5748b29fbf2bcb5df3a063ac52261"
solver-name = "gps-cdcl"
solver-version = 1
There are commands which help you to update/delete/etc packages, please find more info on official github repo of dep (dependency management tool for Go).
go get is the Go package manager. It works in a completely decentralized way and how package discovery still possible without a central package hosting repository.
Besides locating and downloading packages, the other big role of a package manager is handling multiple versions of the same package. Go takes the most minimal and pragmatic approach of any package manager. There is no such thing as multiple versions of a Go package.
go get always pulls from the HEAD of the default branch in the repository. Always. This has two important implications:
As a package author, you must adhere to the stable HEAD philosophy. Your default branch must always be the stable, released version of your package. You must do work in feature branches and only merge when ready to release.
New major versions of your package must have their own repository. Put simply, each major version of your package (following semantic versioning) would have its own repository and thus its own import path.
e.g. github.com/jpoehls/gophermail-v1 and github.com/jpoehls/gophermail-v2.
As someone building an application in Go, the above philosophy really doesn't have a downside. Every import path is a stable API. There are no version numbers to worry about. Awesome!
For more details : http://zduck.com/2014/go-and-package-versioning/
The approach I've found workable is git's submodule system. Using that you can submodule in a given version of the code and upgrading/downgrading is explicit and recorded - never haphazard.
The folder structure I've taken with this is:
+ myproject
++ src
+++ myproject
+++ github.com
++++ submoduled_project of some kind.
That worked for me
GO111MODULE=on go get -u github.com/segmentio/aws-okta#v0.22.1
There's a go edit -replace command to append a specific commit (even from another forked repository) on top of the current version of a package.
What's cool about this option, is that you don't need to know the exact pseudo version beforehand, just the commit hash id.
For example, I'm using the stable version of package "github.com/onsi/ginkgo v1.8.0".
Now I want - without modifying this line of required package in go.mod - to append a patch from my fork, on top of the ginkgo version:
$ GO111MODULE="on" go mod edit -replace=github.com/onsi/ginkgo=github.com/manosnoam/ginkgo#d6423c2
After the first time you build or test your module, GO will try to pull the new version, and then generate the "replace" line with the correct pseudo version. For example in my case, it will add on the bottom of go.mod:
replace github.com/onsi/ginkgo => github.com/manosnoam/ginkgo v0.0.0-20190902135631-1995eead7451
It might be useful.
Just type this into your command prompt while cd your/package/src/
go get github.com/go-gl/mathgl#v1.0.0
You get specific revision of package in question right into your source code, ready to use in import statement.
The current way to do this is to use go install
https://golang.org/doc/go-get-install-deprecation
Starting in Go 1.17, installing executables with go get is deprecated. go install may be used instead.
go install github.com/someone/some_module
Specific version
go install github.com/someone/some_module#v1.1.0
Specific commit
go install github.com/someone/some_module#commit_hash

Resources