I have a go project that is starting to become more complex, and want to lay the filesystem out in such a way to reduce pain.
Are there some good examples out there of what makes sense?
I have a go project that is starting to become more complex, and want to lay the filesystem out in such a way to reduce pain.
Are there some good examples out there of what makes sense?
I assume that with 'project' you don't mean a Go package but a software you develop. Otherwise you can get help here and here. However it's not so much different to writing packages for Go: Use packages, create a folder for each package and combine those packages in your application.
To build yourself an opinion, you can look at trending Go repositories on github: https://github.com/trending/go. Notable examples are cayley and zeus.
The most popular scheme is probably to have a main Go file and many modules and submodules in their own directories. In case you have many meta files (doc, license, templates, ...) you may want to put the source code into a subdirectory. That's what I did so far.
You should probably also have a look into this repo. It shows a lot of ideas how to structure go applications: https://github.com/golang-standards/project-layout
Update May 2013: the official documentation is in the section "Code organization"
src
contains Go source files organized into packages (one package per directory),pkg
contains package objects, andbin
contains executable commands.Update July 2014: see "Structuring Applications in Go" from Ben Johnson
That article include tips like:
Separate your binary from your application
Library driven development
Don’t go crazy with subpackages
Note: that last practice isn't always good:
(Alternative February 2013, regarding
src
only)You can find the classic layout illustrated in "GitHub Code Layout":
That attracted some criticisms though, in this reddit page:
There is a recommended approach from the authors of Golang that defines how to layout your code to work best with the go tools and to support source control systems