From 45c3c78b2ab77f947a4c8f0475b941f2f73b134b Mon Sep 17 00:00:00 2001 From: Paul Balogh Date: Sat, 4 May 2024 10:49:28 -0500 Subject: [PATCH] Configure Air for hot-reloads Use the 'make develop' target to start the service in hot-reload development mode. Signed-off-by: Paul Balogh --- .air.toml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 8 ++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 .air.toml diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..4c53850 --- /dev/null +++ b/.air.toml @@ -0,0 +1,46 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "./bin/weesvc" + cmd = "go build -o ./bin/weesvc .; ./bin/weesvc migrate" + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = true + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/Makefile b/Makefile index 3358e8a..57ae0ff 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ vet: setup: echo "Installing tools..." go install golang.org/x/tools/cmd/goimports@latest - + go install github.com/cosmtrek/air@latest ## build: Build the application. build: deps imports fmt vet build-only @@ -107,8 +107,12 @@ build-docker: release-docker: build-docker docker push $(DOCKER_IMAGE):$(DOCKER_TAG) +## develop: Start the application in hot-reload mode. +develop: build-only + air -c ./.air.toml -- serve + .PHONY: build build-all \ clean clean-all clean-artifacts \ - deps fmt help imports \ + deps develop fmt help imports \ setup test vet