Autocompile Go

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 ?= go GOBUILD = $(GOCMD) build GOCLEAN = $(GOCMD) clean GOTEST = $(GOCMD) test GOGET = $(GOCMD) get BINARY_NAME = project_name BINARY_UNIX = $(BINARY_NAME)_unix default: all all: test build build: $(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: ...

August 21, 2021 · 1 min · Aleem Isiaka