Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adopting an idiomatic repository layout #1

Closed
stapelberg opened this issue Jul 31, 2017 · 7 comments
Closed

Consider adopting an idiomatic repository layout #1

stapelberg opened this issue Jul 31, 2017 · 7 comments

Comments

@stapelberg
Copy link

Thanks for publishing this!

Currently, your import paths don’t resolve: you use e.g. github.com/jmmv/sourcachefs/fs in code, but go get will not be able to download that package, because it lives in src/github.com/jmmv/sourcachefs/fs instead of fs.

This decision affects many downstream tools, such as godoc.org (for automatic API documentation) or packaging helpers (making it hard to package sourcachefs for Debian and others).

Please consider structuring your repository like so:

  1. Place the source directly in your repository, i.e. mv src/github.com/jmmv/sourcachefs/* .
  2. Place packages which are not supposed to be used by others in an internal subdirectory. See https://docs.google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/edit
  3. (Place executable commands in a cmd subdirectory, e.g. cmd/sourcachefs.)
  4. If you need specific versions or custom patches to dependencies, vendor them using the https://github.com/golang/dep tool.

For an example of this structure, see e.g. https://github.com/Debian/debiman/

The end result should be that users will be able to install/update your software using go get -u github.com/jmmv/sourcachefs/cmd/sourcachefs.

Thanks for considering.

@jmmv
Copy link
Owner

jmmv commented Jul 31, 2017

Aha, thanks for the details. Yes, I'll do this. I had no idea about what I was doing :-P

@jmmv
Copy link
Owner

jmmv commented Aug 3, 2017

OK, this may be a stupid question... but how do I build my own code from HEAD if I do this?

go build cmd/sourcachefs or similar all fail. Am I supposed to just check out my code into the GOPATH (by means of go get) and edit it from there? Yikes.

@stapelberg
Copy link
Author

go install github.com/jmmv/sourcachefs/cmd/sourcachefs is what I’d use. The binary will end up in $GOPATH/bin.

Alternatives:

(cd cmd/sourcachefs && go build)

go build ./cmd/sourcachefs (this will store the result in $PWD, which might not be what you want)

@jmmv
Copy link
Owner

jmmv commented Aug 3, 2017

I can see how "end users" will be able to just fetch the code and build/install it with go build and go install if I follow your proposal.

But that's not the problem I have. What I'm talking with "building from HEAD" is... I do:

  1. cd ~/os # Directory where I keep all my projects.
  2. git clone https://github.com/jmmv/sourcachefs
  3. cd sourcachefs
  4. go build ??? # What goes here?

If I try the go build ./cmd/sourcachefs that you mention, Go does indeed find the code... but then, it of course complains about all imports of the form github.com/jmmv/sourcachefs/... to be missing.

@stapelberg
Copy link
Author

Ah: you need to keep the project in your $GOPATH. You could use:

export GOPATH=~/os
cd ~/os
mkdir -p src/github.com/jmmv
cd src/github.com/jmmv
git clone git@github.com:jmmv/sourcachefs
# …

(Instead of manually creating the directory and cloning, you could also just use go get -u github.com/jmmv/sourcachefs, then change the git remote to authenticated in order to be able to push.)

@jmmv jmmv closed this as completed in 389d8fb Aug 3, 2017
@jmmv
Copy link
Owner

jmmv commented Aug 3, 2017

I think this is now resolved.

@stapelberg
Copy link
Author

Almost: you need a subdirectory within cmd/. Currently, your code is compiled into $GOPATH/bin/cmd. I think it should be cmd/sourcachefs/?

jmmv added a commit that referenced this issue Aug 3, 2017
This is to further address the recommendations expressed in issue #1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants