I have a pretty simple Go project that I'm trying to restructure so that it follows the normal Go project structure (and so I can run go build
).
I currently have two source files, both with package main
. All the files, including a few text configuration files that my program needs at runtime.
So right now, it looks like:
<project_name>
- main.go
- source2.go
- config_file.txt
I can run go build
when I'm in this directory, and it creates one binary (named <project_name>
. This works fine, but I'd like to set this up to better follow the Go standard package structure (specifically so that Intellij IDEA will recognize it as a valid project).
Right now, I have the entire <project_name>
directory in Git, and I'd like to keep it that way.
I tried putting the source files in a folder called src
, but then go build
says there aren't any source files to compile.
How should I structure this?
EDIT:
Figured out the issue with putting stuff in src/
: I need to run go build <project_name>
.
I'm still wondering if there's a way to set up a project without a global GOPATH. I have all my projects under one folder, with a subfolder for each project (not all the projects are Go project). I'd like to keep that system.
What I want is:
projects/
- project 1/
- src/
- bin/
- pkg/
- project 2/
- src/
- bin/
- pkg/
Then I'd like to be able to run go build <project_name>
(while I'm in that project's directory) and have it compile that project. Is that possible?
is how `go get` operates. Don't think of the `src` folder as containing a mess of code: it's just a collection of package source code (as opposed to binaries or headers). My GOPATH contains a bunch of `github.com/user/` folders for different packages I've downloaded, a bunch of `code.google.com/project` folders for other packages I've downloaded and of course my own projects. I make this a tad easier by symlinking my own projects into somewhere more accessible without having to mess with my GOPATH.