将 pubsub 与 golang 结合使用:ocgrpc.NewClientStatsHandler

Using pubsub with golang: ocgrpc.NewClientStatsHandler

我正在按照本教程从 golang 项目向 Pub/Sub 发布主题,这是我目前为该项目准备的代码:

package main

import "cloud.google.com/go/pubsub"
import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

它所做的只是简单地导入 pubsub 但是当我 运行 go get 我得到这个错误:undefined: ocgrpc.NewClientStatsHandler

C:\Users\iha001\Dev\golang-projects\src\github.com\naguibihab\golang-playarea\src\gcloud>go get
# cloud.google.com/go/pubsub
..\..\..\..\..\cloud.google.com\go\pubsub\go18.go:34:51: undefined: ocgrpc.NewClientStatsHandler

我还需要安装什么才能获得这个 运行ning 吗?

这似乎是 repo 上的一个问题:

@naguibihab This is NOT a windows issue. This commit fixes the problem be072a5. Short explanation: breaking changes where pushed on a minor release of a google pubsub dependency: census-instrumentation/opencensus-go@ac82455, method NewClientStatsHandler was deleted. (They don't claim anywhere they comply with semver).

这是该评论中提到的修复方法:https://github.com/GoogleCloudPlatform/google-cloud-go/commit/be072a5d1d73144ae0ce1071e9bd43d1ad221581

我在 mac 上遇到了同样的问题,使用的是 "cloud.google.com/go/pubsub" 版本 0.19.0。对我来说,修复是将版本降低到 0.18.0。