- 我是很喜歡
beego
框架bee
工具的熱啟動效果,感覺爽到不能呼吸。但是用gin
框架去開發的時候,就發現難受的很~~ - 所以,經過我在網上這頓搜,發現了一個好玩意兒,
Air
Air是啥玩意兒啊?
這是一個能夠檢測項目代碼變化的插件,支持熱啟動,我一看,擦,想啥來啥!
Air的安裝
-
go
go get -u github.com/cosmtrek/air
-
MacOS
curl -fLo air https://git.io/darwin_air
-
Linux
curl -fLo air https://git.io/linux_air
-
Windows
curl -fLo air.exe https://git.io/windows_air
-
Docker
docker run -it --rm \ -w "<PROJECT>" \ -e "air_wd=<PROJECT>" \ -v $(pwd):<PROJECT> \ -p <PORT>:<APP SERVER PORT> \ cosmtrek/air -c <CONF> # 然后按照下面的方式在docker中運行你的項目 docker run -it --rm \ -w "/go/src/github.com/cosmtrek/hub" \ -v $(pwd):/go/src/github.com/cosmtrek/hub \ -p 9090:9090 \ cosmtrek/air
咋用啊?
-
為了一會兒爽,先把
alias air='~/.air'
這句添加到你的(也是我的).bashrc
或者.zshrc
中,別問,問就是為了一會兒爽! -
進入你的項目目錄
cd /path/to/your_project
-
在當前目錄創建一個新的配置文件
.air.conf
-
將下面這些內容復制到
.air.conf
配置文件中,可以根據你的喜好去改# [Air](https://github.com/cosmtrek/air) TOML 格式的配置文件 # 工作目錄 # 使用 . 或絕對路徑,請注意 `tmp_dir` 目錄必須在 `root` 目錄下 root = "." tmp_dir = "tmp" [build] # 只需要寫你平常編譯使用的shell命令。你也可以使用 `make` # Windows平台示例: cmd = "go build -o ./tmp/main.exe ." cmd = "go build -o ./tmp/main ." # 由`cmd`命令得到的二進制文件名 # Windows平台示例:bin = "tmp/main.exe" bin = "tmp/main" # 自定義執行程序的命令,可以添加額外的編譯標識例如添加 GIN_MODE=release # Windows平台示例:full_bin = "./tmp/main.exe" full_bin = "APP_ENV=dev APP_USER=air ./tmp/main" # 監聽以下文件擴展名的文件. 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
-
直接在項目目錄下,運行
air
爽到不能呼吸!