如何使用供应商依赖项组织一个 Go 项目?

huangapple go评论87阅读模式
英文:

How to organise a Go project with vendorised dependencies?

问题

我正在处理一个Go项目,它不是一个包,而是一个服务。它依赖于mgo和其他一些东西。由于这个服务在法律上要求具有安全版本和高可用性,我们决定将mgo依赖项嵌入到项目中。由于法律要求,我们不能仅仅依赖于从origin/master拉取的任意版本的依赖项。

显然,这会破坏所有标准命令的GOPATH,因为它不再位于GOPATH下,而是在Git仓库的vendor目录中:

~/src/link_tracker/
  main.go
  main_test.go
  vendor/
    src/
      labix.org/
        等等...

我们目前正在使用一个相当丑陋的Bash脚本来解决这个问题,它会修改许多环境变量并进行一些符号链接,但如果我们能将所有这些都整合到一个Makefile或类似的东西下面会更好。

在不丢失我们特定版本的mgo依赖项的情况下,最好/正确的组织方式是什么?

英文:

I'm working on a Go project that isn't a package but a service. It depends on mgo, among other things. Because this service is legally supposed to be securely versioned and highly available we've made the decision to vendorize the mgo dependency within the project. Due to the legal requirement we can't just rely on pulling whatever version is on origin/master for the dependency.

Obviously this breaks our GOPATH for all standard commands as it's no longer living under GOPATH but in a vendor directory within the Git repository:

<pre><code>~/src/link_tracker/
main.go
main_test.go
vendor/
src/
labix.org/
etc...
</code></pre>

We're currently working around this using a fairly ugly Bash script that mangle lots of environment variables and does some symlinking, but it'd be nice if we could consolidate all this under a Makefile or similar.

What's the best/right way to organise this without losing our specifically versioned dependency of mgo?

答案1

得分: 1

你现在应该使用https://github.com/kr/godep来解决这个问题,它非常稳定。需要注意的是,你的代码应该在一个代码库(如git、svn、mercurial等)中。

英文:

You should use https://github.com/kr/godep to solve this problem now is very stable, the thing to have on account is that your code should be on a repository(git, svn, mercurial , among others).

答案2

得分: 0

我一直在使用两个类似目标的工具:

你应该看看是否可以使用其中一个而不是自己编写。在labix.org的情况下,johnny-deps似乎要求使用git托管。

英文:

The two tools I've been playing with (for similar goals) are:

You should probably see if you can use one of them instead of rolling your own. In the particular case of the labix.org stuff, johnny-deps appears to require things to be git-hosted.

huangapple
  • 本文由 发表于 2014年1月3日 22:13:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/20905582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定