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

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

问题描述

我正在尝试使用这个 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 作为值(即我正在尝试使用的这个结构).所以在我的程序中,我同时导入了 Yelp API 包和 guregu 的 null 包,并尝试声明结构体,ip.Lat 和 ip.Lat 是 float64s.(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)我也试过直接导入vendored包,导致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 上的 vendoring 的讨论,了解更多想法/原因.

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

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