protoc-gen-go specific version require - go

I need a pre build project and I need a version of protoc-gen-go v1.25.0-devel but I am unable to find command etc to install It , till now I tried to do something like this :
go get -u google.golang.org/protobuf/cmd/protoc-gen-go#v1.25.0-devel
and I am getting this ERROR invalid version: unknown revision cmd/protoc-gen-go/v1.25.0-devel
Is there any way to get this version ?

If you're following this post to create a sample service, you don't need the specific version 1.25.0-devel that appears in the generated files. You should use the latest stable version (currently v1.26.0). Since it is an minor version upgrade, there should be no breaking changes between versions. One thing that you may need to make the examples in the post to work is that you should set the package for the generated code. You can set it in the .proto file as an option, for example option go_package = grpc-example/generated/protos/calc or as a command line argument for the protoc command, for example protoc ...OTHER_OPTS --go_opt=Mprotos/calc.proto=grpc-example/generated/protos/calc.
If you are sure that you absolutely need the specific version v1.25.0-devel you can install the plugin pointing to a specific commit (as that version is not currently available as a tag/branch name). If you're using go 1.16.x you can use go install google.golang.org/grpc/cmd/protoc-gen-go-grpc#a9513eb pointing at this commit. For older go versions, use go get

Related

Why go get downloads two versions of same package when using -u

I was using go get -u to get a package which depends on golang.org/x/text#v0.3.7. I noticed that it first downloads golang.org/x/text#v0.3.7 then downloads golang.org/x/text#v0.4.0.
Then I ran go clean -modcache and go get golang.org/x/text which downloaded v0.4.0 of golang.org/x/text and then again go get -u entgo.io/ent. This time go didn't download golang.org/x/text#v0.3.7
So, Why go get -u downloads both the old version and latest version when the latest version is not present locally, and Why it doesn't download the old version when the latest version is available locally?
Because it is a two-step process of
Getting dependencies
Updating dependencies
From a programming standpoint there is no good reason to merge these into a single concern of "Get latest dependencies".
From the go command documentation:
The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available.
This means that -u specifically deals with modules which the package you are getting depends on, rather than with the module of the package you are getting.
Furthermore, it appears that -u is agnostic to the Go idiom of treating any change in a v0 version as a major version change, so one cannot lightheartedly recommend using -u out of principle. The README of golang.org/x/test even says:
Until version 1.0.0 of x/text is reached, the minor version is considered a major version. So going from 0.1.0 to 0.2.0 is considered to be a major version bump.

No version set for command go

I attempted to check the version of my go executable with go version on an Ubuntu machine, however I got the following error:
No version set for command go
Consider adding one of the following versions in your config file at
golang 1.16.8
golang 1.17.1
How do I resolve this? I have no prior experience with config file, I searched on google but I found nothing which could solve this issue.
That seems to be an error message from asdf-vm/asdf, a tool which manages multiple runtime versions with a single CLI tool, extendable via plugins.
You can see that error message in asdf-vm/asdf issue 838.
The config file should be in $HOME/.tool-versions
To resolve this, as in this example:
asdf plugin add go
asdf install go latest

go get fetching a pre-release version always

I am trying to wrap my head around go modules. This is what I have done so far.
Created a simple module and published it as 0.0.1 on github.
Referenced the above mentioned module in a separate go project and used it.
so far it works fine. Now I update the initial module to 0.0.2 and publish it as a release on github. Now when I try go get <published module> it still seems to fetch the original 0.0.1 version and run it. I also deleted all references to 0.0.1 including in go.mod and go.sum and run go get and it still fetches the original 0.0.1 version instead of 0.0.2.
I also tried publishing a major version 1.0.0 and tried to use it, but its still fetching the older 0.0.1 version. I thought it will automatically fetch the latest version and use that.
My go.mod file also shows the following even for the major version
require github.com/user/module v0.0.0-20210223020204-1b5fb712826f // indirect
I feel there could be something wrong in the way its being published on git. Any help, anyone.
It looks like the comments already highlighted the required steps to take, but to capture the information in an answer, here is the relevant snippet from go help get
The -u flag instructs get to use the network to update the named packages
and their dependencies. By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.
Basically, go get will only fetch the versions locked in your go.{mod,sum} files and you need to explicitly ask for updates using one of:
# upgrade to the latest release
go get -u github.com/user/module
# upgrade to a specific version
go get github.com/user/module#2.0.0
# use the `latest` version alias
go get github.com/user/module#latest

go run doesnt get the latest tag

I'm playing with GraphQL in Go and I was trying to get gqlgen tool using the familiar go run command.
I was expecting it to retrieve the latest available tag, instead I"m somehow getting a tag which does not seem to exist in the repo at all:
$ go run github.com/99designs/gqlgen version
v0.9.1-dev
I would expect the above to return per the latest tag
v0.13.0
Go version installed on my workstation:
$ go version
go version go1.15.5 darwin/amd64
Anyone has any ideas what's going on?
UPDATE: disabling GOPROXY does not help
UPDATE2: it turns out the version is hardcoded into version.go as you can see here, but even if go run gets the master instead of the latest tag, you'd still expect the output to be 0.13.0-dev as per the master branch Instead I suspect there is some string ordering of versions of tags which orders 0.9.* above 0.1*.*
go run does not currently support running a specific version of a binary, but note that there is an accepted Go proposal to add that functionality in a future release of the go command.
As of Go 1.16, you can instead go install the binary at a specific version, and then run that binary from its install location (either $(go env GOBIN) or $(go env GOPATH)/bin).
$ GOBIN=~/bin go install github.com/99designs/gqlgen#latest
$ ~/bin/gqlgen ...
I think the version command was misconfigured on build, and that v0.9.1-dev was not the tag at build time.

How can I install a specific version of golint for use globally?

I'm trying to create a docker image for use in a build pipeline that has various tools pre-installed for building and testing go projects. One tool we need is golint but I'm struggling to see how to install a specific version of it. The reason I want to lock down the version is to avoid accidental / unwanted / unintended breakages at a later date.
For a start, looking here the versions are not exactly in an easy-to-type format.
Also when I try to use the following command
go get -u golang.org/x/lint/golint#v0.0.0-20181217174547-8f45f776aaf1
I get an error
go: cannot use path#version syntax in GOPATH mode
Googling has so far yielded very few relevant results...
Is what I'm trying to do possible? Many thanks!
You need to be in go module mode to get code of a specific version, since in addition to downloading the code, the version is recorded in the go module file.
The easiest way to do this would be to create an empty directory, run go mod init, which will create a go.mod file.
Then, you can run go get golang.org/x/lint/golint#v0.0.0-20181217174547-8f45f776aaf1, which will add golint at that version to your go.mod file. You can then run go install golang.org/x/lint/golint from within that directory, which will install golint at the version specified into your $GOBIN directory (which defaults to $GOPATH/bin).

Resources