2

I'm trying to use grpc "google.golang.org/grpc" package.

import (
    "github.com/xxxx/yyyy"
    "google.golang.org/grpc"
)

conn, err := grpc.Dial(address)
pppp.NewXXXXClient(conn) // where pppp is from github.com/xxxx/yyyy

What happens if github.com/xxxx/yyyy also vendors the same grpc package? I am getting a compilation error like below

cannot use conn (type *"google.golang.org/grpc".ClientConn) as type
*"github.com/xxxx/yyyy/vendor/google.golang.org/grpc".ClientConn

How can I get around this?

leopoodle
  • 2,110
  • 7
  • 24
  • 36
  • Show the very line that triggers that compilation error. – zerkms Dec 05 '17 at 23:46
  • @zerkms it is added now. – leopoodle Dec 05 '17 at 23:53
  • 1
    You can’t import the same packages from multiple paths. Move the vendored packages from your dependencies into the top level vendor directory. – JimB Dec 06 '17 at 00:05
  • 1
    Nested vendoring is a real pain to deal with and no solution is ideal. Your easiest option is to manually delete the vendored package from xxxx/yyyy. If that fails because it is using a different version of grpc, vendor that version into your own project and leave it deleted from the external one. – PassKit Dec 06 '17 at 00:14
  • @SteveHe: you should vendor that package so you do have control over it. – JimB Dec 06 '17 at 00:24
  • This is why it's generally considered bad practice to vendor dependencies in a library; vendoring should only be used for binaries. – Adrian Dec 06 '17 at 15:55

1 Answers1

-1

I think, you must vendor every dependency of your project (if necessary - include Go std library too), or you shouldn't use vendoring at all. There's no third choise.

Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64