简体   繁体   中英

go 1.18 in google.cloud

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM