golang安装air实现热加载
安装方法分版本稍微不同
// 1.16及其以前go
go get -u github.com/cosmtrek/air
//1.16及其以后install github.com/cosmtrek/air@latest
在项目根目录下进行安装,且需要创建一个配置文件。(与main.go同级)
我们是在windows下所以编译后的文件名为main.exe,如果是linux下main即可。
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main.exe"
cmd = "go build -o ./tmp/main.exe ."
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"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false
配置文件准备好后,就可以开启一个cmd(管理员模式),切换到项目目录,运行air命令,结果类似如下图。
air