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 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?