PROJECTNAME=$(shell basename "$(PWD)")# Go related variables.
GOBASE=$(shell pwd)
GOPATH=$(GOBASE)/vendor:$(GOBASE):/home/azer/code/golang # You can remove or change the path after last colon.
GOBIN=$(GOBASE)/bin
GOFILES=$(wildcard *.go)# Redirect error output to a file, so we can show it in development mode.
STDERR=/tmp/.$(PROJECTNAME)-stderr.txt
# PID file will store the server process id when it's running on development mode
PID=/tmp/.$(PROJECTNAME)-api-server.pid
# Make is verbose in Linux. Make it silent.
MAKEFLAGS += --silent

In the rest of the Makefile, we'll be using especially GOPATH variable heavily. All our commands should be wrapped
with the project specific GOPATH, otherwise they won't work. This provides a clear isolation between our
Go projects, and brings some complexity. To make things easier, we can add an exec command that takes
executes any given command with custom GOPATH defined above.

This is not high-level enough though. We should cover some common cases with simple commands,
and only use exec if we're doing something not covered by the makefile.

Development-mode

Development-mode should;

Clean up the build cache

Compile the code

Run server on background

Repeat the steps above when code changes.

It sounds simple, but gets complicated quickly, as we'll run server and file watcher at same time.
We need to make sure stopping properly before starting a new process, and also not to break
common command-line behavior like stopping when Control-C or Control-D is pressed.

Now we got a watch command that watches for changes recursively in the project directory excluding vendor directory.
We can simply pass any run command we want. For example, start command basically calls make compile start-server when code changes:

make watch run="make compile start-server"

We can use it for running tests, or checking if there is any race condition automatically. Environment variables will be set for the execution,
so you don't have to worry about GOPATH at all:

make watch run="go test ./..."

A nice thing about Yolo is its web interface. If you enable it, you can see the output of your command in a web interface instantly.
All you need is to pass -a option to enable it:

yolo -i . -e vendor -e bin -c "go run foobar.go" -a localhost:9001

Then you can open localhost:9001 in your browser and start seeing results in your browser instantly:

Installing Dependencies

As we make changes in the code, we'd like missing dependencies to be downloaded before compiling. install command will do that job for us;

install: go-get

We'll automate calling install on file change before compiling, so dependencies will get installed automatically.
If you'd like to install a dependency manually, you can run;

The command below basically scans the Makefile for lines starting with ## and outputs them. So, you can simply
comment the commands that you defined, and those comments will be used by the help command.