Live code reloading for Golang web projects in 19 lines

Oleg Lebedev
Dec 9, 2014 · 2 min read
PID      = /tmp/awesome-golang-project.pid
GO_FILES = $(wildcard *.go)
APP = ./app
serve: restart
@fswatch -o . | xargs -n1 -I{} make restart || make kill

kill:
@kill `cat $(PID)` || true

before:
@echo "actually do nothing"
$(APP): $(GO_FILES)
@go build $? -o $@
restart: kill before $(APP)
@app & echo $$! > $(PID)

.PHONY: serve restart kill before # let's go to reserve rules names
$ brew install fswatch # if you don't have
$ make serve

    Oleg Lebedev

    Written by

    Software developer — https://github.com/olebedev

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade