Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

Problems using the Google Cloud go library for logging

I am trying to use import "cloud.google.com/go/logging" with the Go example code found here: https://cloud.google.com/logging/docs/reference/libraries#using_the_client_library . With go1.15.6, I tried these things:

$ 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 -v
cloud.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```
question from:https://stackoverflow.com/questions/65617575/problems-using-the-google-cloud-go-library-for-logging

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thanks to JimB (https://stackoverflow.com/users/32880/jimb) who provided a comment at this question Problems installing GCP go library for logging (which was rudely closed by people who don't want to try to help) that pointed in the direction of this answer.

The problem here is that you are not using modules and the Google Cloud library only supports use that way. This means you do not use go get ... at all, despite the documentation at https://cloud.google.com/logging/docs/reference/libraries#client-libraries-install-go . Instead, start by creating this go.mod file:

module example.com/mymod

go 1.15

require (
    cloud.google.com/go/logging v1.1.2
)

Then, run go build -i -v which will install all the required modules.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...