有没有一种方法可以对Go项目中的导入使用可重用的路径? [英] Is there a way to have reusable pathing for imports on Go projects?
问题描述
我在Go上很新,需要一些帮助,以使导入路径在我的团队之间更可分配.
I am very new at Go, and need a bit of help with a way to make import pathing more distributable between my team.
当前在我的一个Go文件的顶部,我有一个导入文件,说"github.teamName.com/teamMemberA/HeartThrob/c"
Currently at the top of one of my Go files, I have an import, say "github.teamName.com/teamMemberA/HeartThrob/c"
我用自己的名字分叉了他的项目,并下载了该项目,但出现了一些非常明显的导入错误.
I forked his project to my own name and downloaded it and got some pretty obvious import errors.
我要导入的文件的我的路径如下:"github.teamName.com/myName/HeartThrob/c"
MY path to the file it is trying to import is the following: "github.teamName.com/myName/HeartThrob/c"
此重大变化是因为我正在从自己的分叉存储库中提取项目.
This pathing change is because I am pulling the project from my own forked repo.
如何解决此问题?相对路径可行吗?由于项目的大小和一些明显的分隔位置,我无法将所有Go文件放入同一目录中.
What is a way I can go about fixing this? Is relative pathing possible? I can't put all the Go files into the same directory due to the size of the project and some obvious places for separation.
免责声明:GO AND Git的新手(虽然我的分叉方法是团队强制性的)
Disclaimer: New to Go AND Git (My forked approach is team-mandated though)
推荐答案
假定GOPATH包含单个元素,请执行以下操作:
Assuming that GOPATH contains a single element, do this:
$ mkdir -p $GOPATH/github.teamName.com/teamMemberA
$ cd $GOPATH/github.teamName.com/teamMemberA
$ git clone github.teamName.com/myName/HeartThrob
$ cd HeartThrob/c
$ go install
另一种方法是:
$ go get github.teamName.com/teamMemberA/HeartThrob/c
$ cd $GOPATH/github.teamName.com/teamMemberA/HeartThrob
$ git remote add fork git@github.myName/HeartThrob.git
别无所求,然后再推叉.
Hack a way and push to fork.
这篇关于有没有一种方法可以对Go项目中的导入使用可重用的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!