正确构建Golang项目

I have a project structure that looks like so:

enter image description hereI was planning on just using a shell script (build.sh) to set GOPATH and build the project.

I am not sure how to build a Golang project properly, my short term goal is to just to build the packages in the src directory and put the binaries into the bin directory.

I am not sure what go build command can do that, I have tried a few things.

So first my question is - is this a reasonable project structure and second, how can I compile my src directory to bin?

What I have gives me the following error:

can't load package: package .: no buildable Go source files in /home/oleg/WebstormProjects/oresoftware/stack-server

So I believe I need to tell Go to look in the src directory, because Go is only looking for .go files in the project root, but I am not sure how to do that.

If it matters, the main.go file has a package name of "main".

GOPATH=$PROJECT_DIR && cd $PROJECT_DIR && go install main

Also move your main.go file into src/main/main.go.

This will produce a bin/main executable.

If you have multiple executables you wanna build, you have to put each main.go file into a separate folder/package. The name of the generated executable is taken from the directory name the file is inside. The package name of the main.go files must always be main if it should create a binary.

To compile multiple executables you have to use:

GOPATH=$PROJECT_DIR && cd $PROJECT_DIR && go install ...

The ... matches all folders/packages.