英文:
Godep processing custom packages
问题
这是我的问题。
我有一个使用我自己创建的一些自定义包的go-app。
我不想将这些包发布到git或其他地方。
它们只是具有某些特定功能的包。
所以,我的项目文件夹看起来像这样:
|--src/github/u-mulder
|--/project_name
|--/Godeps
|--/public
|--/vendor
|--main.go
|--Procfile
我将我的包放在vendor
文件夹中:
-/Godeps
-/public
-/vendor
|---/github.com/u-mulder/package_one/package_one.go
|---/github.com/u-mulder/package_two/package_two.go
-main.go
-Procfile
好的,在我的main.go
中,我成功地导入了这些包:
import (
"database/sql"
"fmt"
"github.com/u-mulder/package_one"
"github.com/u-mulder/package_two"
// 这里还有更多的包
)
一切都正常工作。
现在,我想使用godep
准备我的项目以便部署到Heroku。
所以,在我的项目的根文件夹中,我运行了以下命令:
> godep save ./...
这里出现了我的问题 - 因为我的包已经在vendor
文件夹中,所以我收到了错误消息:
godep: 找不到包(github.com/u-mulder/package_one)
当然,我可以为每个包创建一个项目。然后,src
的结构将如下所示:
|--src/github/u-mulder
|--/package_one
|-package_one.go
|--/package_two
|-package_two.go
|--/project_name
|--/Godeps
|--/public
|--/vendor
|--main.go
|--Procfile
然后上述提到的问题就解决了,但是又出现了第二个问题:
godep: 在检查
"$GOPATH/src/github.com/u-mulder/package_one"
时出错:目录"$GOPATH/src/github.com/u-mulder/package_one"
没有使用已知的版本控制系统
当然,我可以在每个项目包中创建一个.git
仓库(也许这个问题就解决了),但我不想这样做,因为这些只是我自己使用的本地包。
所以,问题是 - 在哪里放置我的自定义(或者说本地)包,以便godep
可以找到它们,并且不要求它们是“真正的”包?
我在这里找到了类似的内容,但它不是关于vendor
文件夹的。
英文:
Here's my problem.
I have go-app which uses some custom packages I created by myself.
I don't want to publish this packages on git or elsewhere.
They're just packages with some certain functionality.
So, my project folder looks like this:
|--src/github/u-mulder
|--/project_name
|--/Godeps
|--/public
|--/vendor
|--main.go
|--Procfile
I place my packages to vendor
folder:
-/Godeps
-/public
-/vendor
|---/github.com/u-mulder/package_one/package_one.go
|---/github.com/u-mulder/package_two/package_two.go
-main.go
-Procfile
Okay, in my main.go
I successfully import this packages:
import (
"database/sql"
"fmt"
"github.com/u-mulder/package_one"
"github.com/u-mulder/package_two"
// more packages here
)
And everything works fine.
Now I want to prepare my project for deploying to heroku using godep
.
So, in a root folder of my project I run
> godep save ./...
And here comes my problem - as my packages are already in a vendor
folder, I receive error:
> godep: Package (github.com/u-mulder/package_one) not found
Sure, I can create a project for every of my packages. Then the structure of src
will look like:
|--src/github/u-mulder
|--/package_one
|-package_one.go
|--/package_two
|-package_two.go
|--/project_name
|--/Godeps
|--/public
|--/vendor
|--main.go
|--Procfile
Then the above mentioned problem is gone, but the second one appears:
> godep: error while inspecting "$GOPATH/src/github.com/u-mulder/package_one"
: directory "$GOPATH/src/github.com/u-mulder/package_one"
is not using a known version control system
So, of course I can create a .git
repository in each project package (and maybe this problem will be gone), but I don't want, these are just local packages for my use only.
So, the question is - where to place my custom (or say - local) packages so godep
can find them and don't want them to be "real" packages?
Something similar I found here, but it's not about vendor
folder.
答案1
得分: 1
感谢@JimB的评论,我找到了以下信息:
最明显和简单的解决方案就是:
在GOPATH中保留您的依赖项,并进行版本控制,然后让godep处理它们(@JimB)
所以是的,这意味着将包添加到git中以及其他相关操作。
如果您不想或无法这样做,操作的顺序可以是:
- 编写代码
- 进行测试
- 从
vendor
中删除您的本地依赖项(包) - 运行
godep
以更新其他依赖项(如httprouter
,libpq
等) - 手动将您的本地依赖项添加回
vendor
- 提交更改
但显然这__不是__一个好的方法。
英文:
Thanks to @JimB comments I found out the following:
the most obvious and simple solution is just
> keep your dependencies in GOPATH, with version control, and just let godep handle them all (@JimB)
So yes, this means adding package(s) to git and all this stuff.
In case if you don't want/can't do that, the order of actions can be:
- Code
- Test
- Remove your local dependecies (packages) from
vendor
- Run
godep
to update other dependecies (likehttprouter
,libpq
, etc) - Manually add your local dependecies back to
vendor
- Commit
But obvioulsy it is not a good way.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论