包的类型不能用作供应商的包的类型 [英] package's type cannot be used as the vendored package's type

查看:83
本文介绍了包的类型不能用作供应商的包的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此 Golang Yelp API包.在某些结构中,它使用 guregu的空包中定义的类型.

I'm trying to use this Golang Yelp API package. In some of its structs, it uses types defined in guregu's null package.

我想声明一个在Yelp API包中定义的结构,其中的某些字段将null.Float作为值((null.FloatFrom定义):

I want to declare a struct defined in the Yelp API package, where some of its fields have null.Float as a value (i.e. this struct, which im trying to use). So in my program, I import both the Yelp API package and guregu's null package and try to declare the struct, with ip.Lat and ip.Lat being 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         }

但是当我运行程序时,它告诉我:

But when I run the program, it tells me:

./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)我也尝试直接导入供应商的软件包,这导致Go告诉我use of vendored package not allowed.

1) I did not import the null package, which caused Go to complain about null being undefined. 2) I also tried importing the vendored package directly, which caused Go to tell me use of vendored package not allowed.

关于如何解决此问题的任何想法?

Any Ideas on how to fix this?

推荐答案

这里的解决方案似乎是我正在尝试使用的库需要重新设计,以防止此类事情发生.

The solution here seems to be that the library I'm trying to use needs to be reworked to prevent this kind of thing from happening.

更改库的两种可能方法似乎是

The two possible ways to change the library seem to be

1)完全不是供应商-如果依赖项不需要是特定版本,则可以使用此功能.

1) not vendor at all - this works if the dependency does not need to be a specific version.

2)供应商提供的,但不要将供应商的库公开.在库中创建一些包装函数,以便人们可以间接创建类型.

2) vendored, but do not expose the vendored library to the public. Create some wrapper functions in the library so that people can create the types indirectly.

请参见有关reddit上供应商的讨论,以了解更多想法/原因.

这篇关于包的类型不能用作供应商的包的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆