Live code reloading for Golang web projects in 19 lines

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

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

@echo "actually do nothing"
@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 —

    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