在Go项目中,有没有一种可以重复使用的导入路径的方法?

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

Is there a way to have reusable pathing for imports on Go projects?

问题

我在Go方面非常新手,需要一些关于如何使导入路径在我的团队之间更具可分发性的帮助。

目前,在我的一个Go文件的顶部,我有一个导入路径,比如说"github.teamName.com/teamMemberA/HeartThrob/c"。

我将他的项目fork到了我的名字下,并下载了它,但是遇到了一些明显的导入错误。

我尝试导入的文件的路径是:"github.teamName.com/myName/HeartThrob/c"。

这个路径的改变是因为我从自己fork的仓库中拉取项目。

有什么方法可以解决这个问题吗?是否可以使用相对路径?由于项目的规模和一些明显的分离点,我不能将所有的Go文件放在同一个目录中。

免责声明:我对Go和Git都很陌生(尽管我的fork方法是团队规定的)。

英文:

I am very new at Go, and need a bit of help with a way to make import pathing more distributable between my team.

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.

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.

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.

Disclaimer: New to Go AND Git (My forked approach is team-mandated though)

答案1

得分: 2

假设GOPATH只包含一个元素,按照以下步骤操作:

$ 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

进行修改并推送到fork。

英文:

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

An alternative approach is:

$ 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.

huangapple
  • 本文由 发表于 2015年2月14日 06:57:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/28510180.html
匿名

发表评论

匿名网友

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

确定