在Google Cloud中使用Go 1.18

huangapple go评论91阅读模式
英文:

go 1.18 in google.cloud

问题

描述

我正在尝试从一个使用Go v1.18程序安装一个库,以便访问Google Cloud。
以前使用的是"go get"命令,但自从1.18版本以后,它不再可用。
似乎要使用"go install",但在执行该命令时出现错误。

% 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

环境

% 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

参考资料

bigquery package - cloud.google.com/go/bigquery - pkg.go.dev

我尝试了

感谢您的支持。

% 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

接下来我该怎么办?

自行解决。
-> 将包名更改为"main"。

英文:

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"

答案1

得分: 1

go install 用于安装包中可用的二进制程序。通常用于命令行工具。

在 go1.18 之前,go get 用于更新包并安装程序,他们通过将其拆分为几个程序进行了更改。

似乎没有需要安装的内容。而且主要的包不是 bigquery,而是 cloud.google.com/go。

如果你想安装一个依赖项,如果你正在使用 vendorized 模块,你可以执行以下操作:

$ go get -u cloud.google.com/go/bigquery

$ go mod tidy

$ go mod vendor

如果不是,你可以尝试先运行 go mod init

英文:

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

huangapple
  • 本文由 发表于 2022年4月10日 05:01:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/71811875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定