我正在尝试使用这个 Golang Yelp API package .在其某些结构中,它使用 guregu's null package 中定义的类型.
我想声明一个在 Yelp API 包中定义的结构,其中一些字段将 null.Float
作为值 ( i.e. this struct, which im trying to use )。所以在我的程序中,我导入了 Yelp API 包和 guregu 的 null 包,并尝试声明结构,其中 ip.Lat 和 ip.Lat 是 float64s。 (null.FloatFrom
definition) :
33 locationOptions := yelp.LocationOptions{
34 ip.Zip,
35 &yelp.CoordinateOptions{
36 Latitude: null.FloatFrom(ip.Lat),
37 Longitude: null.FloatFrom(ip.Lon),
38 },
39 }
但是当我运行程序时,它告诉我:
./cli.go:36: cannot use "github.com/guregu/null".FloatFrom(ip.Lat) (type
"github.com/guregu/null".Float) as type "github.com/JustinBeckwith/go-
yelp/yelp/vendor/github.com/guregu/null".Float in field value
我尝试了两件事:
1)我没有导入null
包,导致Go报错null
未定义。 2) 我还尝试直接导入 vendored 包,这导致 Go 告诉我 use of vendored package not allowed
。
关于如何解决这个问题有什么想法吗?
最佳答案
这里的解决方案似乎是我尝试使用的库需要重新设计以防止这种事情发生。
两种可能的改库方法好像是
1) 根本不是 vendor - 如果依赖项不需要是特定版本,则此方法有效。
2) 出售,但不要向公众公开出售的库。在库中创建一些包装函数,以便人们可以间接创建类型。
参见 this discussion about vendoring on reddit for more ideas/reasons why.
关于go - 包的类型不能用作 vendored 包的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55159029/