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

北战南征 提交于 2019-12-07 21:15:43

问题


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:


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.



来源:https://stackoverflow.com/questions/28510180/is-there-a-way-to-have-reusable-pathing-for-imports-on-go-projects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!