【发布时间】:2023-04-10 17:37:02
【问题描述】:
我正在尝试使用这个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。
关于如何解决这个问题的任何想法?
【问题讨论】: