go install apache arrow - go

I'm a beginning go user trying to install the go apache arrow module, so I can run the introductory examples in the user guide. When I try to install the library, I receive the following errors:
$ go install github.com/apache/arrow/go#latest
go: github.com/apache/arrow/go#latest:
module github.com/apache/arrow#latest found (v0.0.0-20220326002331-5bd4d8ec279d),
but does not contain package github.com/apache/arrow/go
$ go install github.com/apache/arrow/go#v7.0.0
go: github.com/apache/arrow/go#v7.0.0: github.com/apache/arrow/go#v7.0.0:
invalid version: go/go.mod has post-v7 module path
"github.com/apache/arrow/go/v7" at revision go/v7.0.0
I've been able to install other go packages successfully, so I don't understand why this install is erroring out.
What is the correct invocation of "go install" to install apache arrow?

There is an easy way: assume you have done go mod init in your local project, you can start to write a file and import github.com/apache/arrow/go/v8 Like this example:
https://github.com/apache/arrow/blob/master/go/arrow/_examples/helloworld/main.go
Now you can easily do
go mod tidy && go mod vendor
And the tool should recognize the imports to download and vendorize.
Or you can do explicitly in your project dir,
go get -u github.com/apache/arrow/go/v8
then run the mod tidy and mod vendor

Related

go: module found but does not contain package

I am trying to install the net package for go but get "does not contain package error".
Terminal screenshot:
I have consulted: go module #latest found but does not contain package but none of the solutions seem to work for me.
I am using go version go1.18.5 linux/amd64
You have to initialize your module with go mod init in the project root directory
For local codebase
go mod init test
OR for hosted codebase e.g. github repo: test, github user: radiant
go mod init github.com/radiant/test
It will produce a go.mod file.
Then you can get the required package as:
go get golang.org/x/net
go mod tidy
Then import and use the net packages.
Hope this helps.
go get -u golang.org/x/net
go install used for executable packages

go install failure (but does not contain package golang.org/x/tools)

Problem:
When I run the command: go install golang.org/x/tools#latest
I get the error: go: golang.org/x/tools#latest: module golang.org/x/tools#latest found (v0.1.12), but does not contain package golang.org/x/tools
This started after upgrade from go 1.16 to go 1.18.
Background:
I have a pre build Docker image with go installed where I want to execute go commands, in this specific Docker it is go mockgen commands being executed creating gRPC and rest mocks.
You should use go install golang.org/x/tools/...#latest if you want the packages within.
You can do the same thing with packages in mock:
go install github.com/golang/mock/...#latest

go install #latest found but does not contain package

I'm trying to install my package using go install but I get this error message when running the command go install github.com/JoaoDanielRufino/gcloc/cmd/gcloc#latest:
go install: github.com/JoaoDanielRufino/gcloc/cmd/gcloc#latest: module github.com/JoaoDanielRufino/gcloc#latest found (v1.0.0), but does not contain package github.com/JoaoDanielRufino/gcloc/cmd/gcloc
I want the executable name to be gcloc.
Here is the current source code: https://github.com/JoaoDanielRufino/gcloc
Note: I've already tried go clean -modcache but it didn't work
As the main function of this package isn't on its root, you should pass the directory of the main package on your command.
So, your command will be:
go install -v github.com/JoaoDanielRufino/gcloc/cmd#latest
I came across a similar issue when I was trying to use go install to install the cloudflare/cf-terraforming tool on my machine. The documentation for this tool is not clear on the installation and I had to dig around to get this to work
Basically #Jictyvoo answer above sums it up, if the path is pointing to anything other than directory where the main.go file is sitting I got the error
Command: go install github.com/cloudflare/cf-terraforming#latest v0.8.0#latest
go: github.com/cloudflare/cf-terraforming#latest: module
github.com/cloudflare/cf-terraforming#latest found (v0.8.0), but does not
contain package github.com/cloudflare/cf-terraforming
when I switched to the below it worked fine for me:
Command: go install -v github.com/cloudflare/cf-terraforming/cmd/cf-terraforming#latest
This worked for me after checking the repo and realising that the main.go file was sitting in the cmd/cf-terraforming subdirectory

go run/build not getting dependencies

go run and go build are not geting dependencies.
What I did:
I have done a go get of a package, it fetched it, and its dependencies, and build it. (all is good)
I run its command-line example program. (all is good)
I then created a new program based on this example, and go run it. (all is good)
Then copied this example program, and go run it. ( get a dependency error ).
Transcript
#↳ go version
go version go1.11.4 linux/amd64
#↳ echo $GOPATH
/home/????/+Files/workshops/programming/golang/gopath
#↳ go get -u github.com/cbroglie/mustache/...
#↳ cp -T $GOPATH/src/github.com/cbroglie/mustache/cmd/mustache/main.go my-mustache.go
#↳ go build -v my-mustache.go
my-mustache.go:8:2: cannot find package "github.com/spf13/cobra" in any of:
/usr/local/go/src/github.com/spf13/cobra (from $GOROOT)
/go/src/github.com/spf13/cobra (from $GOPATH)
I can see why it is not already installed: it was in a vendor sub-directory of the original source code. But why does it not install, when I build?
Check first your $GOPATH/bin folder: a go get -u github.com/cbroglie/mustache/... should already have compiled and installed all relevant binaries in it.
The README mentions:
To install mustache.go, simply run go get github.com/cbroglie/mustache/....
From the comments:
It looks like the mustache package is installed and working. However
when I try to build the cli example, it needs another package, if I go
get it then all is well, however I was expecting go build to install
all needed packages. Am I wrong?
go build itself won't install dependencies, so you need to go get it, or activate go 1.11 modules and declare that dependencies in your new program modules.

How to install "gotests" command?

I need to use the test driven development in Go using "gotests" command.
gotests -all *
This is not working. I did go get -u /github.com/cweill/gotests
and go install. But there is no binary created in $GOPATH/bin.
since there is NO main package, Use this command
$ go get github.com/cweill/gotests/...
this itself download all dependencies for the current package, and creates bin file, after downloading this package. see in $GOPATH/bin there will be a bin file named gotests
for more see HERE
The following worked for me with go v1.19.1
go install github.com/cweill/gotests/gotests#latest
Using go get to install things has been disabled since 1.18. See Deprecation of 'go get' for installing executables
go install github.com/rakyll/gotest
Source: https://github.com/rakyll/gotest

Resources