关于golang:使用Air热加载Go程序windows下的配置

8次阅读

共计 921 个字符,预计需要花费 3 分钟才能阅读完成。

Windows 下装置 Air

go env -w GOPROXY=https://goproxy.cn,direct
go env -w GO111MODULE=on

go install github.com/cosmtrek/air@latest

装置当前, 门路退出环境变量配置.

2. 我的项目配置
在我的项目的根目录下创立文件 .air.conf


root = "."
tmp_dir = "tmp"

[build]

# 只须要写你平时编译应用的 shell 命令。你也能够应用 `make`

cmd = "go build -o main.exe ."
# 由 `cmd` 命令失去的二进制文件名

bin = "main.exe"
# 自定义执行程序的命令,能够增加额定的编译标识例如增加 GIN_MODE=release

full_bin = "main.exe"
# 监听以下文件扩展名的文件.
include_ext = ["go", "tpl", "tmpl", "html"]
# 疏忽这些文件扩展名或目录
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# 监听以下指定目录的文件
include_dir = []
# 排除以下文件
exclude_file = []
# 如果文件更改过于频繁,则没有必要在每次更改时都触发构建。能够设置触发构建的延迟时间
delay = 1000 # ms
# 产生构建谬误时,进行运行旧的二进制文件。stop_on_error = true
# air 的日志文件名,该日志文件搁置在你的 `tmp_dir` 中
log = "air_errors.log"

[log]
# 显示日志工夫
time = true

[color]
# 自定义每个局部显示的色彩。如果找不到色彩,应用原始的应用程序日志。main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# 退出时删除 tmp 目录
clean_on_exit = true

3. 应用命令 air 启动我的项目
air.exe -c .air.conf

4、测试
批改代码并保留批改(ctrl+s)
air 会自动检测的批改, 从新加载我的项目.

参考: http://t.zoukankan.com/ztshua…

正文完
 0