简体   繁体   English

Go项目工作区如何与依赖工具和go工具一起使用?

[英]How to do a Go project workspace to work with dependencies tools and go tools?

I have a project with packages inside: 我有一个包含包的项目:

  • project package "root": a/b/c (eg github/b/c) 项目包“ root”: a/b/c (例如github / b / c)
  • in a/b/c we have a lot of packages (p1, p2 ...) a/b/c我们有很多包装(p1,p2 ...)
  • project is managed according to How to Write Go Code official recommendations. 根据如何编写Go Code官方建议管理项目。 The local project path is: $GOPATH/src/a/b/c . 本地项目路径为: $GOPATH/src/a/b/c Also all imports are "not relative". 而且所有进口都是“非相对的”。
  • the project has go get -able dependencies 该项目具有可获取的依赖项

Now I want to use some dependency manager tool like gom or godep . 现在,我想使用一些依赖管理器工具,例如gomgodep Each of this tool creates an extra directory in repository and puts all vendor dependencies there. 每个工具都会在存储库中创建一个额外的目录,并将所有供应商依赖项放在此处。 Also it plays with GOPATH and sets it to that vendor directory. 它还与GOPATH一起GOPATH并将其设置到该供应商目录。 Let's assume that the tool will put all vendors in path_to_project/.vendor - becoming a new GOPATH . 假设该工具将把所有供应商都放在path_to_project/.vendor ,成为一个新的GOPATH

I want to use one of the go tools ( gofmt , gorename , ...) being aware about packages in my projects and vendor directory. 我想使用其中一种go工具( gofmtgorename ,...)来了解我的项目和供应商目录中的软件包。 The problem is that if GOPATH=path_to_project/.vendor ( godep does this) then tools are not aware about packages in my project. 问题是,如果GOPATH=path_to_project/.vendorGodep这样做),那么工具将无法识别我项目中的软件包。

One idea for this is to set a GOPATH=path_to_project/.vendor:GOPATH in a shell end editors. 一种解决方法是在外壳端编辑器中设置GOPATH=path_to_project/.vendor:GOPATH Or call every command with gom exec (gom sets a GOPATH in the above proposition) 或使用gom exec调用每个命令(gom在上述命题中设置了GOPATH)

Is there any ready and automatic solution for this? 是否有任何现成的自动解决方案?

Final goal is to bundle go project with specified dependencies versions (like git commits) and make tools + editors (vim/emacs) working with this tools. 最终目标是将go项目与指定的依赖项版本(例如git commits)捆绑在一起,并使工具+编辑器(vim / emacs)与此工具一起使用。

If you are using godep, you can just prefix the go command with godep like this: 如果您使用的是godep,则可以在go命令前添加godep前缀,如下所示:

godep go build

or 要么

godep go fmt 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM