3

I'm just discovering the Go programming language.

(FWIW, I am fluent in C++, Ocaml, C, Common Lisp, Scheme, I know well Linux, and I have designed & implemented GCC MELT; I am considering a rewrite of some MELT monitor in Go, but have not decided it yet)

I am a bit confused about the required layout of some Go workspace. I still am unease with the notion of packages in Go (they seems similar to Ocaml's modules) and the interfaces in Go (they look like Ocaml's signatures or module types).

The How To Write Go Code document mentions both a pkg/ and a src/ mandatory subdirectory, but Michael Maccanis' Oh shell example don't have any src/ and I was still able to build it using the

 go get github.com/michaelmacinnis/oh

command mentionned in its README.md. Why (and how) does that work (without any src/) ?


If that is important, I'm using go1.8rc2 on Linux/amd-64 (Debian/Sid). I'm trying Go right now (and did not look into it before) because Go 1.8 (scheduled before spring 2017) should have plugins and these are a feature essential to me.

PS. I've read (and liked) the Go for C++ programmer wiki; but I might miss the Go for Ocaml programmer equivalent.

1

Because when you go get something, it is placed under the $GOPATH/src , in the respective folders, depending on what you import. That repo is github.com/michaelmacinnis/oh, so it is cloned to $GOPATH/src/github.com/michaelmacinnis/oh. In pkg, $GOPATH/pkg/github.com/michaelmacinnis/oh, the compiled shared objects for your platform resides, and they are reused for further compilations from other packages, if the source packages are not modified.

In short, the code should be in $GOPATH/src/path/to/repo/code/etc/hi , so when you go get, it puts /path/to/repo/code/etc/hi to $GOPATH/src , it is how go packages are resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.