当前位置:网站首页>go --- air自动重新编译
go --- air自动重新编译
2022-07-27 18:18:00 【谬也】
0、Air介绍
实时监听项目的代码文件,在代码发生变更之后自动重新编译并执行。在使用Go语言的gin框架在本地做开发调试的时候,经常需要在变更代码之后频繁的按下Ctrl+C停止程序并重新编译再执行,这样就不是很方便。
github地址:https://github.com/cosmtrek/air
参考链接:https://www.liwenzhou.com/posts/Go/live_reload_with_air/
1、安装
go install github.com/cosmtrek/[email protected]
2、初始化
air init
默认生成配置文件.air.toml,内容如下:
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
按需修改日志、编译文件位置、编译后执行命令即可
3、准备服务
一个简单的demo
package main
import (
"github.com/gin-gonic/gin"
"net/http"
)
func main() {
r := gin.Default()
r.GET("/hello", func(c *gin.Context) {
c.String(http.StatusOK, "mio")
})
_ = r.Run(":9090")
}
4、启动服务
air

此时监听9090端口
5、测试实时加载
将端口号9090改为9091后保存,看终端中是否重新编译

修改保存后服务重新编译启动,监听端口号变为了9091,测试成功
如有不对,烦请指出,感谢~
边栏推荐
- 学术分享 | 清华大学 康重庆:电力系统碳计量技术与应用(Matlab代码实现)
- js中数组与字符串常用方法属性总结
- Is it safe for CICC fortune to open an account? What is the use of opening an account
- 【效率】弃用 Notepad++,这款开源替代品更牛逼!
- Conversion of Oracle date
- 用户登录切换案例
- 金仓数据库 KingbaseES 异构数据库移植指南 (4. 应用迁移流程)
- Xdc 2022 Intel technology special session: Intel Software and hardware technology builds the cornerstone of cloud computing architecture
- Best practices for Oracle kingbasees migration of Jincang database (4. Oracle database migration practice)
- 认识网络模型数据的封装和解封装
猜你喜欢
![[hierarchical reinforcement learning] HAC paper and code](/img/f5/d5f791d0f9da749eafa912be9dfbb5.png)
[hierarchical reinforcement learning] HAC paper and code

浅析即时通讯移动端 IM 开发中登录请求的优化

leetcode:1498. 满足条件的子序列数目【排序 + 二分 + 幂次哈希表】

Why are TS slice files generated when easycvr platform turns off video recording?

用户登录切换案例

VI working mode (3 kinds) and mode switching (conversion)

Lennix Lai, OKx financial market director: Web3 is a revolution

Arduino开发(二)_基于Arduino UNO开发板的RGB灯光控制方法

Tencent jumped out with 38K and saw the real test ceiling

【深度学习】Pytorch torch.autograd 自动差分引擎
随机推荐
What configurations are required to connect polardb and redis?
走马灯案例
用户登录切换案例
用户和权限限制用户使用资源
软件测试面试题:已知一个队列,如: [1, 3, 5, 7], 如何把第一个数字,放到第三个位置,得到:[3, 5, 1, 7]
How to improve the picture transmission speed and success rate in the development of IM instant messaging under the mobile network
Kingbasees heterogeneous database migration guide (2. Overview)
sql编码bug
(manual) [sqli labs38, 39] stack injection, error echo, character / number type
Injection attack
【阿里安全 × ICDM 2022】20万奖金池!大规模电商图上的风险商品检测赛火热报名中!...
2022-07-19 advanced network engineering (XX) BGP route optimization, route optimization analysis one by one
VI working mode (3 kinds) and mode switching (conversion)
Software test interview question: string "axbyczdj", if you get the result "ABCD"
面了个腾讯拿38K跳槽出来的,见识到了真正的测试天花板
Idea: solve the problem of code without prompt
A new UI testing method: visual perception test
LabVIEW学习笔记五:按钮按下后无法返回原状
【毕设教程】YOLOv7 目标检测网络解读
JVS公众号登陆配置