gin的热启动方案-air

使用gin搭建服务的时候,在开发环境修改代码,要关闭服务,再重新打开代码才能生效。

频繁修改再打开是一个很低效的事情。所以需要一个工具,在修改完代码之后可以热启动。

可以使用 air来完成。

安装

go 复制代码
go install github.com/cosmtrek/air@latest

配置

air不会自动配置路径,需要我们添加

sh 复制代码
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

即可

修改bash zsh

复制代码
vim ~/.zshrc 
# or we can 
# vim ~/.bash_profile

# Add this in the file
alias air='$(go env GOPATH)/bin/air'

这样以后打开的新的终端都可以应用了

相关推荐
ttwuai4 天前
Go开源后台管理系统推荐:怎么按技术栈和边界比较4个官方仓库?
golang·gin
福兮说10 天前
Gin 项目里的错误处理:让 Controller 不必知道错误是怎么来的
后端·go·gin·架构设计
妙码生花14 天前
两个月 59 篇 AI 开发日志 + Golang 商业级实战项目收工后,得来的 AI 使用心法-上
前端·后端·gin
王的宝库15 天前
Gin + GORM
开发语言·golang·gin
妙码生花15 天前
golang 应用服务端部署(使用 systemd 服务)
开发语言·人工智能·后端·golang·node.js·php·gin
JavaPub-rodert18 天前
后台操作日志千万别同步写库:从 ShiyuAdmin 看 Gin 异步审计日志设计
gin
王的宝库18 天前
Gin 框架实战
golang·gin