Autocompile Go
August 21, 2021
First, install CompileDaemon:
$ go get github.com/githubnemo/CompileDaemon && go install github.com/githubnemo/CompileDaemon
Then, from the root of the project, create a Make file:
$ touch Makefile
And add the below content:
GOCMD ?= goGOBUILD = $(GOCMD) buildGOCLEAN = $(GOCMD) cleanGOTEST = $(GOCMD) testGOGET = $(GOCMD) getBINARY_NAME = project_nameBINARY_UNIX = $(BINARY_NAME)_unixdefault: allall: test buildbuild:$(GOBUILD) -o ../$(BINARY_NAME) -v -ldflags="-X main.VERSION=$(TAG)"test:$(GOTEST) -v ./...clean:$(GOCLEAN)rm -f $(BINARY_NAME)rm -f $(BINARY_UNIX)run: build./$(BINARY_NAME)dev:CompileDaemon -build="$(GOBUILD) -o ../$(BINARY_NAME)" -command="../$(BINARY_NAME)" -color="true" -exclude-dir=.git -exclude=".#*"
Finally, from the root of your project:
$ make dev
Voila!
Edit on githubTweet