https://github.com/air-verse/air?tab=readme-ov-file
可以使用这个库实现项目的自动重载
修改代码之后自动重新运行项目
下载
如果是go1.25环境以上的,直接go install下载
go install github.com/air-verse/air@latest
也可以在release里面直接下载可执行文件,然后把它加到环境变量里面
https://github.com/air-verse/air/releases/download/v1.63.4/air_1.63.4_windows_arm64.exe
用法
命令行的用法
air --build.cmd "go build -o bin/api cmd/run.go" --build.entrypoint "./bin/api" --build.exclude_dir "templates,build"
--build.cmd 编译命令
--build.entrypoint 执行的命令
--build.exclude_dir 排除的目录
配置文件的用法
先用air init生成配置文件
air init
配置文件
#:schema https://json.schemastore.org/any.json
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "tmp\\main.exe"
cmd = "go build -o ./tmp/main.exe ."
delay = 1000
entrypoint = ["tmp\\main.exe"]
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
silent = false
time = false
[misc]
clean_on_exit = false
[proxy]
app_port = 0
enabled = false
proxy_port = 0
[screen]
clear_on_rebuild = false
keep_scroll = true
运行时指定配置文件
# 默认就是读取 .air.toml文件
air -c .air.toml