当前位置:网站首页>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,测试成功
如有不对,烦请指出,感谢~
边栏推荐
- 征服所有程序员的3件IT装备 →
- 国际权威认可!OceanBase入选Forrester Translytical数据平台报告
- Best practices for Oracle kingbasees migration of Jincang database (4. Oracle database migration practice)
- JVS基础框架功能列表
- [dataset display annotation] VOC file structure + dataset annotation visualization + code implementation
- 基于ATX自动化测试解决方案
- Why are TS slice files generated when easycvr platform turns off video recording?
- 一周活动速递|深入浅出第8期;Meetup成都站报名进行中
- Understand the wonderful use of dowanward API, and easily grasp kubernetes environment variables
- MySQL log error log
猜你喜欢

EasyCVR平台添加RTSP设备时,出现均以TCP方式连接的现象是什么原因?

Knowledge dry goods: basic storage service novice Experience Camp

When adding RTSP devices to easycvr platform, what is the reason for the phenomenon that they are all connected by TCP?

Idea: solve the problem of code without prompt

【深度学习】视频分类技术整理
![[deep learning] video classification technology sorting](/img/bf/422d4ef342199966bbdaae06977699.png)
[deep learning] video classification technology sorting

金仓数据库 Oracle 至 KingbaseES 迁移最佳实践 (4. Oracle数据库移植实战)

IM即时通讯开发如何提升移动网络下图片传输速度和成功率

如何监控NVIDIA Jetson的的运行状态和使用情况

Session attack
随机推荐
Innovative cases | the growth strategy of digitalization of local life services and upgrading of Gaode brand
MySQL basic queries and operators
Understand │ what is cross domain? How to solve cross domain problems?
用户组织架构的管理
十年测试老鸟聊聊移动端兼容性测试
Common ways to keep requests idempotent
【程序人生】“阶段总结“-不甘平凡
Software test interview question: string "axbyczdj", if you get the result "ABCD"
Understand the wonderful use of dowanward API, and easily grasp kubernetes environment variables
Jetpack compose performance optimization guide - compilation metrics
vant组件库
金仓数据库 Oracle至KingbaseES迁移最佳实践(2. 概述)
Advanced SQL skills CTE and recursive query
[deep learning] video classification technology sorting
One week activity express | in simple terms, issue 8; Meetup Chengdu station registration in progress
Kingbasees heterogeneous database migration guide (4. Application migration process)
[rctf2015]easysql-1 | SQL injection
用户和权限撤销用户权限
Management of user organization structure
Scrollintoview realizes simple anchor location (example: select city list)