douxing1850 2013-06-24 12:04
浏览 67
已采纳

使用标签获取Go软件包依赖关系

How can I fetch all the dependencies of Go packages at once using version tags on specific imports ?

Say I have my go tree with multiple packages in it :

src/
    foo/
        bar/               (go code in package bar)
            x.go
        quux/              (go code in package main)
            y.go

Now let the package `bar' depends on a third party library that use tag versions
(i.e. usually fetched with : go get -tags mylib_2.0 github.com/user/mylib)

What I want to do is to specify a tag on the import line so that go get ./... on my tree gets the correct version scheme. Something like:

import "github.com/user/mylib" `tags=mylib_2.0`
  • 写回答

1条回答 默认 最新

  • doupuzhimuhan9216 2013-06-24 12:43
    关注

    change you project structure too:

    src/
        foo/
            bar/
               v1/    (go code in package bar)
                  x.go
               v2/
                  x.go
            quux/ 
                 v1/   (go code in package main)
                    y.go
    

    this is the only possible way to handle different version of your libs.

    with this you also solve the problem jnml described, now each lib would have its own dependencies and versions to other libs.

    update due to comments:

    according to workspace documentation described here:
    http://golang.org/doc/code.html#Workspaces

    your structure will looke like

    src/
        foo/
            bar/
               v1/    (go code in package bar)
                  x.go
               v2/
                  x.go
            quux/ 
                 v1/   (go code in package main)
                    y.go
            meier/ 
                 v1/   (go code in package main)
                    w.go
                 v2/   (go code in package main)
                    w.go
    

    now in your bar lib (x.go) you need functions from lib *quux (y.go)
    to import this you will write :

    import "foo/quux/v1/"
    

    just as note you can also do the version before package in your structure so instead of foo/quux/v1 your structure could look like /foo/v1/quux, then you dont need to name the imports.

    now lib quux uses lib meier in version 1
    so import will be:

    import "foo/meier/v1"
    

    and regarding to jnml, now you lib bar also needs lib meier but in version 2
    so import will look like:

    import "foo/meier/v2"
    

    now when you call: bar -> quux -> meier
    you will see that you can't assign /pass the return value in bar to something from meier

    because: meier/v1 != meier/v2

    and this will fail already during compilation.

    if you need to work with result from quux which is coming from meier v1 you need to also import meier/v1 in bar

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题