33

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

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

I tried 2 things:

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?

Julien Chien
  • 2,052
  • 4
  • 16
  • 32

4 Answers4

12

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) not vendor at all - this works if the dependency does not need to be a specific version.

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.

See this discussion about vendoring on reddit for more ideas/reasons why.

Julien Chien
  • 2,052
  • 4
  • 16
  • 32
10

I had the same issue. As a work around, I deleted the associated package's vendor folder and moved their content to my $GOPATH folder.

Source of answer: promql Go import problem: use of vendored package not allowed

Abdullah Khawer
  • 4,461
  • 4
  • 29
  • 66
Randy Yuan
  • 101
  • 1
  • 5
4

Just had a similar issue. Putting both libraries in /vendor resolved. Using govendor get xxxx

Viktor Yarmak
  • 181
  • 2
  • 9
1

Had a similar issue while using Godep and I resolved by deleting /vendor and re-running godep save ./... - Hope it helps.

Aldo 'xoen' Giambelluca
  • 12,075
  • 7
  • 33
  • 39