-10

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.

Community
  • 1
  • 1
u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • Why are you using a "github.com" path if your sources aren't on github? Even for local packages, you should be using a version control of some sort. godep can't version the package if there's no version control. – JimB Dec 15 '16 at 14:28
  • @JimB Ok, I can change path to my packages to something else (`local` or whatever) but that doesn't help. And all my project is under version control (otherwise I can't place it on heroku). – u_mulder Dec 15 '16 at 14:32
  • But you said in the question that you don't want to create a git repo for each package, so I'm confused as to what you're trying to do. If you've already vendored all the required packages, what is it you want godep to achieve? – JimB Dec 15 '16 at 15:06
  • Hmmm, I put my packages in `vendor` folder, manually. Then I use `godep save ./...` and get a described error `Package not found`. Also I should mention that there other packages in `vendor` (`libpq` for example) which are processed correctly. – u_mulder Dec 15 '16 at 15:25
  • If the packages are already in the vendor folder, then what is godep supposed to do? `godep save` records the "source control revision" of the package found in GOPATH, then copies that to the vendor folder. If the package is already in `vendor/`, and doesn't have any revision control, then there's nothing godep can do. – JimB Dec 15 '16 at 15:29
  • So I suppose that I should first run `godep` for updating/adding external dependencies (like `libpq` for example), then - manually place my packages into `vendor` and after that - commit? – u_mulder Dec 15 '16 at 16:31
  • Or, you could keep your dependencies in GOPATH, with version control, and just let godep handle them all. – JimB Dec 15 '16 at 16:33
  • @JimB Sure, but the case was that I want to avoid that) But anyway, thanks. Not sure what should I do with the question) – u_mulder Dec 15 '16 at 16:36

1 Answers1

1

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.

u_mulder
  • 54,101
  • 5
  • 48
  • 64