From 1845002f9d48120bc0862df6ab33c68f40c3b339 Mon Sep 17 00:00:00 2001 From: engigu Date: Tue, 10 Feb 2026 14:35:10 +0800 Subject: [PATCH] feat: support air reload --- .air.toml | 44 ++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 5 ++++- Makefile | 15 ++++++++++----- 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 .air.toml diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..360ce9e --- /dev/null +++ b/.air.toml @@ -0,0 +1,44 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "bin" + +[build] + args_bin = [] + bin = "./bin/baihu" + cmd = ":" + full_bin = "go run main.go" + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata", "web", "data", "envs", "configs", "bin"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = true + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = false + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/.gitignore b/.gitignore index 7688636..26beb11 100644 --- a/.gitignore +++ b/.gitignore @@ -48,4 +48,7 @@ configs/config.local.json __pycache__/ # Misc -.stfolder \ No newline at end of file +.stfolder + +bin/ + diff --git a/Makefile b/Makefile index 312a9d1..5e32cd8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Variables -BINARY=baihu +BINARY=bin/baihu GOBUILD=go build GOCLEAN=go clean GOGET=go get @@ -19,6 +19,7 @@ build-web: # Build the application (requires frontend to be built first) build: + @mkdir -p bin CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY) main.go # Build all (frontend + backend) @@ -59,20 +60,24 @@ build-agent-darwin-arm64: # Clean built files clean: $(GOCLEAN) - rm -f $(BINARY) + rm -rf bin/ rm -rf internal/static/dist mkdir -p internal/static/dist touch internal/static/dist/.gitkeep # Run the application run: + @mkdir -p bin $(GOBUILD) -o $(BINARY) main.go ./$(BINARY) -# Development run (without embedding frontend) +# Development run with hot reload (both frontend and backend) dev: - $(GOBUILD) -o $(BINARY) main.go - ./$(BINARY) + @command -v air > /dev/null 2>&1 || go install github.com/air-verse/air@latest + @command -v concurrently > /dev/null 2>&1 || npm install -g concurrently + concurrently --kill-others \ + "air" \ + "cd web && npm run dev" # Install dependencies deps: