Description
I am trying to install a library from a go v1.18 program to access Google Cloud.
Previously, the "go get" command was used, but since version 1.18, it is no longer available.
It seems to use go install, but I get an error when executing the command.
% go install cloud.google.com/go/bigquery
go: 'go install' requires a version when current directory is not in a module
Try 'go install cloud.google.com/go/bigquery#latest' to install the latest version
% go install cloud.google.com/go/bigquery#latest
package cloud.google.com/go/bigquery is not a main package
% go install cloud.google.com/go#latest
package cloud.google.com/go is not a main package
Environments
% go version
go version go1.18 darwin/amd64
% uname -v
Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
% sw_vers
ProductName: macOS
ProductVersion: 12.3.1
BuildVersion: 21E258
Reference
bigquery package - cloud.google.com/go/bigquery - pkg.go.dev
I tried,
Thank you for your support.
% go mod init cloud.google.com/go
% go get -u cloud.google.com/go/datacatalog
go: added cloud.google.com/go/datacatalog v1.3.0
% go mod tidy
go: downloading google.golang.org/appengine v1.6.7
go: downloading golang.org/x/sys v0.0.0-20220209214540-3681064d5158
% go mod vendor
% go run catalog.go
package command-line-arguments is not a main package
What should I do next ?
Self resolved.
-> change package name "main"
go install is used to install binary programs available on the package. Usually command line tools.
go get, until go1.18, was used to update packages and install programs, they change it by split in several programs
Seems there is nothing to install. Also the main package is not bigquery but cloud.google.com/go
If you want to install a dependency, if you are using vendorized modules you can do
$ go get -u cloud.google.com/go/bigquery
$ go mod tidy
$ go mod vendor
If not, you may try it by running go mod init first
Related
I am installing golint package in my CI pipeline and I am using Go v1.16. Now because of golint, it installs sys v0.2.0 even if golint's go.mod file has specific versioned dependencies.
golint installs golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 (https://github.com/golang/lint/blob/master/go.mod)
gotools installs golang.org/x/net v0.0.0-20190620200207-3b0461eec859 (https://github.com/golang/tools/blob/2f3ba24bd6e75104fb11be4edf062de340ffd1ab/go.mod)
x/net installs golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a (https://github.com/golang/net/blob/3b0461eec859c4b73bb64fdc8285971fd33e3938/go.mod)
Which is not v0.2.0. But still sys having v0.2.0 is being installed and because of that other code/stages fails with error:
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/syscall.go:83:16: undefined: unsafe.Slice
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
/go/pkg/mod/golang.org/x/sys#v0.2.0/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice
I have also checked release dates for sys here: https://github.com/golang/sys/tags and the above mentioned sys version is from past (from 2019) and it should work with Go v1.16.
What am I missing here?
I tried to install this subzy tool from GitHub but it shows this kind of error and I can't install it I have faced the same problem with other programs written in (GO language).
I can clone the programs written in python but I am unable to clone the programs written in go language once I clone I don't know how to install them
****➜ ~ go install -v github.com/lukasikic/subzy#latest
go: finding a module f**or package github.com/mitchellh/go-homedir
go: finding module for package github.com/logrusorgru/aurora
go: found github.com/logrusorgru/aurora in github.com/logrusorgru/aurora v2.0.3+incompatible
go: found github.com/mitchellh/go-homedir in github.com/mitchellh/go-homedir v1.1.0
➜ ~ go get -u -v github.com/lukasikic/subzy
go get: installing executables with 'go get' in module mode is deprecated.
Use 'go install pkg#version' instead.
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
➜ ~**
Welcome to the community,
Check the closed repo, whether it has go.mod and go.sum files
Check the version of the go (go mod is enforced in recent version meaning)
Check and learn about go mod and how to use (https://go.dev/blog/using-go-modules)
I want to install this tool from github : https://github.com/ethicalhackingplayground/ssrf-tool
I am using the cmd : go install github.com/ethicalhackingplayground/ssrf-tool#latest
Output :
go: finding module for package github.com/projectdiscovery/gologger
go: finding module for package github.com/briandowns/spinner
go: finding module for package github.com/logrusorgru/aurora
go: found github.com/briandowns/spinner in github.com/briandowns/spinner v1.18.1
go: found github.com/logrusorgru/aurora in github.com/logrusorgru/aurora v2.0.3+incompatible
go: found github.com/projectdiscovery/gologger in github.com/projectdiscovery/gologger v1.1.4
# github.com/ethicalhackingplayground/ssrf-tool
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:34:2: undefined: gologger.Printf
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:35:2: undefined: gologger.Infof
..\..\..\go\pkg\mod\github.com\ethicalhackingplayground\ssrf-tool#v0.0.0-20200901082948-7f3cffc3c7bb\ssrftool.go:36:2: undefined: gologger.Infof
I am super new to golang, go installation is fine in my system because other tools from github are working fine.
If some changes are required in the code of this tool, please suggest so.
This sources created without go module support and an old version of gologger, here is a workaround:
Clone repository git clone git#github.com:ethicalhackingplayground/ssrf-tool.git
cd ssrf-tool create go.mod file with content:
module github.com/ethicalhackingplayground/ssrf-tool
go 1.17
require (
github.com/briandowns/spinner v1.18.1
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/projectdiscovery/gologger v1.0.1
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 // indirect
)
download deps go mod download
Build executable go build .
./ssrf-tool --help
Profit.
Here is the repo with the problem fixed.
go install github.com/R0X4R/ssrf-tool#latest
or
git clone https://github.com/R0X4R/ssrf-tool.git
cd ssrf-tool
go build ssrftool.go && mv ssrftool /usr/bin/
go list -m -versions gopkg.in/urfave/cli.v1 gives me the following version listing, that has 1.20.0 as the newest version:
gopkg.in/urfave/cli.v1 v1.0.0 v1.1.0 v1.2.0 v1.3.0 v1.3.1 v1.4.0 v1.4.1 v1.5.0 v1.6.0 v1.7.0 v1.7.1 v1.8.0 v1.9.0 v1.10.0 v1.10.1 v1.10.2 v1.11.0 v1.11.1 v1.12.0 v1.13.0 v1.14.0 v1.15.0 v1.16.0 v1.16.1 v1.17.0 v1.17.1 v1.18.0 v1.18.1 v1.19.0 v1.19.1 v1.20.0
However, according gopkg.in, 1.22.4 should be the newest version. 1.22.4 is also the newest release on the package's GitHub repo.
How should I go troubleshooting this problem? Seems like it could be a cache issue.
For background info: the repository originally had dep-based dependency listing (Gopkg.toml), that had version 1.20. I prefer modules, so I initialised go.mod by go mod init $REPO_URL. I later pulled the latest commits from the repo, which had the package version updated to 1.22. I tried re-creating go.mod; it first indicated a problem at that step:
go: converting Gopkg.lock: stat gopkg.in/urfave/cli.v1#v1.22.0: gopkg.in/urfave/cli.v1#v1.22.0: invalid version: go.mod has non-....v1 module path "github.com/urfave/cli" at revision v1.22.0
In the end, I ended up with code that expects version 1.22, but the tools fetch the version 1.20 which isn't forwards compatible, so it doesn't compile.
There is nothing you can do to fix it. The package is broken, so the package author/maintainer needs to fix it.
In short, the project has an invalid go.mod file, which was apparently added after v1.20.0 was released--which is why up to that version is available.
The go.mod file refers to "github.com/urfave/cli", but the package is imported as "gopkg.in/urfave/cli.v1". The go.mod file needs to be updated to reflect the proper import path.
As a work-around, it might work to import the package as "github.com/urfave/cli", but this will break many packages that have "sub" packages that refer to the alternate import path. I'd say it's worth a try in this case, though.
I have a package that uses some local packages
module mycompany.com/clientname/server
go 1.14
require (
github.com/lib/pq v1.7.0
github.com/99designs/gqlgen v0.11.3
github.com/vektah/gqlparser/v2 v2.0.1
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
mycompany.com/clientname/models v0.0.0-00010101000000-000000000000
mycompany.com/common/utils v0.0.0-00010101000000-000000000000
)
replace mycompany.com/common/utils => ../../common/utils
replace mycompany.com/clientname/models => ../models
the mycompany.com domain doesn't serve the package, it is just a fictional path (and I use it in my gopath ~/go/src/mycompany.com/...)
the problem is that when I run go get -u all, I want the 'valid' packages to be updated (like the github.com/lib/pq or github.com/99designs/gqlgen), but to leave the local (fictional) packages as they are.
but go get -u all just prints out the new versions, then prints the errors on the local packages and then doesn't change go.mod.
go: google.golang.org/grpc upgrade => v1.30.0
go: go.opencensus.io upgrade => v0.22.4
go: github.com/mattn/go-runewidth upgrade => v0.0.9
go: github.com/gogs/chardet upgrade => v0.0.0-20191104214054-4b6791f73a28
go: golang.org/x/text upgrade => v0.3.3
go: github.com/mitchellh/mapstructure upgrade => v1.3.2
go get all: unrecognized import path "mycompany.com/clientname/models": reading https://mycompany.com/clientname/models?go-get=1: 404 Not Found
go get all: unrecognized import path "mycompany.com/common/utils": reading https://mycompany.com/common/utils?go-get=1: 404 Not Found
The error from go get -u was a bug in the go command, fixed in the upcoming Go 1.16 release. See https://golang.org/issue/32567 for detail.
(That said, ideally you should be hosting the modules in version control and using GOPRIVATE=mycompany.com instead of slotting things in locally via replace directives.)