溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

goland服務(wù)怎么利用配置文件進(jìn)行熱重啟

發(fā)布時(shí)間:2020-12-04 15:29:16 來源:億速云 閱讀:287 作者:Leah 欄目:開發(fā)技術(shù)

這篇文章給大家介紹goland服務(wù)怎么利用配置文件進(jìn)行熱重啟,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

開發(fā)web api或web項(xiàng)目,修改源碼后,無需手動(dòng)重啟即可查看效果,使用air即可實(shí)現(xiàn)。

安裝air:go get -v -u github.com/cosmtrek/air(或下載所有源碼后,go build,得到air.exe,拷貝到$goroot/bin目錄)

在項(xiàng)目目錄下,創(chuàng)建.air.config文件,修改[build]中的cmd配置,設(shè)置為goland編譯程序的命令行命令:

cmd = "go build -o ./tmp/xxx-demo.exe ./main.go"

最終配置文件如下:

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
 
# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"
 
[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/xxx-demo.exe ./main.go"
# Binary file yields from `cmd`.
bin = "tmp/xxx-demo.exe"
# 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 = []
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop to run old binary when build errors occur.
stop_on_error = true
# This log file places in your tmp_dir.
log = "air_errors.log"
 
[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

goland中打開項(xiàng)目,在Terminal中運(yùn)行air命令,即可自動(dòng)監(jiān)控項(xiàng)目代碼修改,自動(dòng)熱啟動(dòng)服務(wù),方便開發(fā)調(diào)試。

關(guān)于goland服務(wù)怎么利用配置文件進(jìn)行熱重啟就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI