公司為了提高研發效率,想要讓我搞一下熱部署,然后就上網上查熱部署,發現有好多工具可以完成這個效果,就挑了一個比較不錯的air,使用過后也是感覺非常不錯的,下面來說說怎么用。
先說一下air的特性:
1)彩色日志輸出
2)自定義構建或二進制命令
3)支持忽略子目錄
4)啟動后支持監聽新目錄
5)更好的構建過程
安裝:
在命令行中輸入go get -u github.com/cosmtrek/air
使用:
為了我們能夠好的使用命令行操作,我們需要把alias air='~/.air'加到你的.bashrc或.zshrc中,根據你的系統進行選擇,因為我是mac,所以我將alias air='~/.air'加到了vim ~/.zshrc中了。
# 1. 進入你自己的項目目錄
$ cd /your_project
# 2. 查找你的項目中是否存在 `.air.conf` 配置文件
$ air -c .air.conf
# 3. 沒有則創建一個
$ touch .air.conf
# 4. 復制下面示例 `air.conf.example`到你的 `.air.conf`
# 5. 啟動熱加載
$ air
# 6. 啟動熱加載 帶打印log
$ air -d
air.conf.example示例
root = "."
tmp_dir = "tmp"
[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms
[log]
# Show log time
time = false
[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
[misc]
# Delete tmp directory on exit
clean_on_exit = true
原文鏈接:https://blog.csdn.net/qq_39397165/article/details/108025397
