2017-07-28 108 views
0

依赖是围棋的一个问题,但是这是新的东西:直接依赖于库BC 依赖三角

  • 图书馆B

    • 应用A直接取决于库C

    如果我们在应用代码A中有这样的事情:

    funcyInstance := &C.FuncyObject{} 
    B.CleverFunction(funcyInstance) 
    

    当LIB B

    func CleverFunction(arg *C.FuncyObject) {} 
    

    它提出了一个错误:

    cannot use funcyInstance (type "*A/vendor/github.com/C".FuncyObject) as type "*B/vendor/github.com/C".FuncyObject in argument to B.CleverFunction

    我使用滑翔作为一个依赖管理。

    我知道这种依赖关系的配置会导致存在几种类型而不是单个类型(对于所有库),并且可能它只是Go的反模式。无论如何...如何解决这个问题?

  • +1

    你不应该嵌套供应商目录。它看起来像'glide'有一个'--strip-vendor'选项,而不是因为某些原因默认。 – JimB

    回答

    1

    我删除vendor文件夹下B,并把Cvendor文件夹(应用程序A如果我正确地得到您的结构)。

    这样,你只能得到每种类型的一个地方。

    不知道为什么B将有一个vendor文件夹中的首位,因为滑翔的建议很清楚,在此:

    http://glide.readthedocs.io/en/latest/vendor/

    Libraries (codebases without a main package) should not store outside packages in a vendor/ folder

    In applications (codebases with a main package) there should only be one vendor/ directory at the top level