Skip to content

Instantly share code, notes, and snippets.

@koungkub
Last active August 16, 2021 13:22
Show Gist options
  • Save koungkub/f37b60d1020dc2b4fd688a55e4e62307 to your computer and use it in GitHub Desktop.
Save koungkub/f37b60d1020dc2b4fd688a55e4e62307 to your computer and use it in GitHub Desktop.
Nodemon for golang
# Inspire by -> https://medium.com/@olebedev/live-code-reloading-for-golang-web-projects-in-19-lines-8b2e8777b1ea
PID = /tmp/nodemon-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 "\nRESTARTED ..."
$(APP): $(GO_FILES)
@go build -o $@
restart: kill before $(APP)
@$(APP) & echo $$! > $(PID)
.PHONY: serve restart kill before
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment