dongyi9298 2016-12-15 13:52
浏览 68
已采纳

Godep处理定制包

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条回答 默认 最新

  • dphg63476 2016-12-15 16:44
    关注

    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 (like httprouter, libpq, etc)
    • Manually add your local dependecies back to vendor
    • Commit

    But obvioulsy it is not a good way.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集