在本地导入Go包而不是远程导入。

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

Importing Go packages locally rather than remotely

问题

在一个Node.js项目中,我正在使用Go来处理Node无法处理的关键部分。我想将Go代码分成一个sockets包和一个main包,其中sockets包含main包运行所需的结构体/接口。我遇到的问题是,根据我从Go的文档中了解到的,我只能从github/gopkg等地方使用像sockets这样的外部包。我不想将项目的存储库分成一个包含Go代码的存储库和一个包含Node代码的存储库。我该如何使sockets包在本地可供main导入,同时又能够在源代码更新时重新构建这两个包的二进制文件呢?

编辑:导入包不再是问题,但在更新时重新构建包仍然存在。

英文:

In a node.js project, I'm using Go for a critical part of it that node isn't adequate enough to handle. I want to split the Go code into a sockets package and a main package, with sockets containing required structs/interfaces for the main package to run. The problem I'm having is that from what I can gather from Go's documentation, I can only use external packages like sockets remotely from github/gopkg. I don't want to split the repository for the project into one containing the Go code and one containing node's. How can I make the sockets package available for main to import locally while making it possible to rebuild the binaries for the two packages if any updates to their source code are made?

Edit: importing the packages is no longer an issue, but rebuilding packages on update still remains

答案1

得分: 1

这也发生在我的团队身上,我们最终使用了供应商(vendor)来管理所有的外部包,这样任何检出你的仓库的人都会在供应商文件夹中找到所有的包。

了解和使用供应商文件夹:Understanding and using the vendor folder

此外,请参考这个网站,还有很多其他选项可供选择:Golang Package Management Tools

英文:

It happens the same to my team too and we end up using vendor it's pretty easy to manage all the external packages. So, whoever checkout your repo will have all the packages inside vendor.

Understanding and using the vendor folder

And Please refer this site lots of other option out there too:

Golang Package Management Tools

huangapple
  • 本文由 发表于 2017年1月15日 10:36:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/41657255.html
匿名

发表评论

匿名网友

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

确定