为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Google Cloud go 库进行日志记录时遇到的问题

使用 Google Cloud go 库进行日志记录时遇到的问题

Go
偶然的你 2022-08-01 15:14:16
我正在尝试与此处找到的Go示例代码一起使用:https://cloud.google.com/logging/docs/reference/libraries#using_the_client_library。在go1.15.6中,我尝试了以下方法:import "cloud.google.com/go/logging"$ go get -u cloud.google.com/go/logging# many errors about dependencies, so$ go get -u github.com/google/go-cmp/cmp$ go get -u golang.org/x/sync/semaphore# then I can get through this one$ go get -u cloud.google.com/go/logging# for further amusement, these two fail with what seems to be a compiler error$ go get cloud.google.com/go/storage$ go get cloud.google.com/go/iam# Then trying to build my code using Logging:$ go build -i -vcloud.google.com/go/logging/apiv2# cloud.google.com/go/logging/apiv2../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:269:62: undefined: logging.ListBucketsRequest../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:310:60: undefined: logging.GetBucketRequest../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:310:114: undefined: logging.LogBucket../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:328:63: undefined: logging.CreateBucketRequest../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:328:120: undefined: logging.LogBucket../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:354:63: undefined: logging.UpdateBucketRequest../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:354:120: undefined: logging.LogBucket../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:374:63: undefined: logging.DeleteBucketRequest../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:825:14: undefined: logging.LogBucket../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:840:65: undefined: logging.LogBucket../../go/src/cloud.google.com/go/logging/apiv2/config_client.go:374:63: too many errors```
查看完整描述

1 回答

?
繁华开满天机

TA贡献1816条经验 获得超4个赞

在这个问题上提供了评论 安装GCP go库进行日志记录的问题(被不想尝试帮助的人粗鲁地关闭了),这指向了这个答案的方向。


这里的问题是你没有使用模块,谷歌云库只支持使用这种方式。这意味着您根本不使用,尽管 https://cloud.google.com/logging/docs/reference/libraries#client-libraries-install-go 上的文档。相反,请先创建以下 go.mod 文件:go get ...


module example.com/mymod


go 1.15


require (

    cloud.google.com/go/logging v1.1.2

)

然后,运行它将安装所有必需的模块。go build -i -v


查看完整回答
反对 回复 2022-08-01
  • 1 回答
  • 0 关注
  • 101 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信