使用gin搭建服务的时候,在开发环境修改代码,要关闭服务,再重新打开代码才能生效。
频繁修改再打开是一个很低效的事情。所以需要一个工具,在修改完代码之后可以热启动。
可以使用 air来完成。
安装
go install github.com/cosmtrek/air@latest
配置
air
不会自动配置路径,需要我们添加
alias air='$(go env GOPATH)/bin/air'
然后添加一个air的配置文件
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
args_bin = []
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
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
执行命令
air
即可文章来源:https://www.toymoban.com/news/detail-620108.html
修改bash zsh
vim ~/.zshrc
# or we can
# vim ~/.bash_profile
# Add this in the file
alias air='$(go env GOPATH)/bin/air'
这样以后打开的新的终端都可以应用了文章来源地址https://www.toymoban.com/news/detail-620108.html
到了这里,关于gin的热启动方案-air的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!