mypackage/
README.md
src/
mypackage/
mypackage.go
mypackage_test.go
myapp/
README.md
src/
myapp/
myapp.go
myapp_test.go
package main
import(
"github.com/jmcvetta/mypackage"
)
func main() {
mypackage.DoSomething()
println("Woot, woot - we did something!")
}
package github.com/jmcvetta/mypackage
imports github.com/jmcvetta/mypackage
imports github.com/jmcvetta/mypackage: no Go source files in /home/jason/work/myapp/src/github.com/jmcvetta/mypackage
You're confusing the GOPATH workspace directory layout with the perpackage directory layout.
Many people make this mistake and it seems largely due to incorrect
assumptions based on experiences with some other language's package
layouts.
import ()
$GOPATH/src/jmcvetta/tokenizer/tokenizerd/
On Wed, Apr 25, 2012 at 6:31 PM, Jesse McNelis <jes...@jessta.id.au> wrote:
You're confusing the GOPATH workspace directory layout with the perpackage directory layout.Thanks - I see that now.Many people make this mistake and it seems largely due to incorrect
assumptions based on experiences with some other language's package
layouts.There was definitely an assumption about workflow that caught me up. In other languages (e.g. Python & Ruby) I am accustomed to fetch some code from a repository, descend into the checkout, and start work there. Although in practice I usually check out code into my ~/work/ folder, that's just convention - the workflow goes exactly the same if I checkout into e.g. ~/foo/bar/. These assumptions may have been helped along by Goclipse, which maps a Go workspace (containing potentially many different repo checkouts) onto an Eclipse "project". Other Eclipse tools. e.g. Pydev map a single application (from a single repo) onto an Eclipse "project".It seems that when one wants to work on some Go code, one needs to checkout the repo into an existing workspace's src folder. A repo is not a self-contained project. One thing that made this more confusing to me, is that using a workspace seems necessary only when developing code, to make the go tool happy. If I just want to compile existing code, I can check out the repo, set GOPATH = repo root, issue "go get . && go build .", and it works fine.Another thing that confused me was the location within a Go workspace where I should check out my various repos. A real example is a little app I am writing called 'tokenizerd', which depends on a library 'tokenizer'. Both packages live on github. The two are developed concurrently, so both should be writable checkouts. Tokenizerd uses a github path to import tokenizer:import ()
If I check out both repos into $GOPATH/src, build fails because tokenizer package cannot be found. Instead a folder tree like this seems best:$GOPATH/src/jmcvetta/tokenizer/
tokenizerd/Although things would work okay if tokenizerd were directly below src, to me it feels better if all my checkouts live under the same folder.
The downside to this layout is that short commands like "go test tokenizerd" don't work. Instead you need to say "go test github.com/jmcvetta/tokenizerd".
Although things would work okay if tokenizerd were directly below src, to me it feels better if all my checkouts live under the same folder.That tree looks correct. There should be a .git directory below each of those "leaf" directories. What about it doesn't work for you?
The downside to this layout is that short commands like "go test tokenizerd" don't work. Instead you need to say "go test github.com/jmcvetta/tokenizerd".go test ...tokenizerd
If you go get a package, it puts it in the right place.
The rest (and there are lots of other things that could be included) is hard to put in that document because it would be information overload!
On Fri, Apr 27, 2012 at 2:58 PM, Kyle Lemons <kev...@google.com> wrote:
If you go get a package, it puts it in the right place.Go get fetches a read-only checkout of the repo. That helped confuse me, because I took it as a hint that go get (and the path where it installs code) was just for installing external packages I don't plan to edit.
It would be helpful if the doc included an example of how to work on a command and its dependency package(s), at the same time.
The rest (and there are lots of other things that could be included) is hard to put in that document because it would be information overload!For sure the doc should avoid bloat and stay short. But if a lot of newcomers are asking similar questions, that suggests there is room for improvement in the wording.
It's not read-only per-se. The default github https checkouts are, but that's not a go-get issue, that's a github and git scm nuance, and I don't think it applies to bitbucket or googlecode hg checkouts.
I have made wiki posts to try to help new Gophers, but I am no longer one and thus am only speculating about what such "common questions" would be. It would be much more beneficial if new Gophers themselves shared such tips *hint hint* ;-).