当前位置:网站首页>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,测试成功
如有不对,烦请指出,感谢~
边栏推荐
- Tencent jumped out with 38K and saw the real test ceiling
- Interviewer: what is the abstract factory model?
- 【Dart】一门为跨端开发而生的编程语言
- [Alibaba security × ICDM 2022] 200000 bonus pool! The risk commodity inspection competition on the large-scale e-commerce map is in hot registration
- Using dataX to realize efficient synchronization of MySQL data
- Ten year test old bird talk about mobile terminal compatibility test
- Write bootloader from 0
- 说透缓存一致性与内存屏障
- Babbitt | metauniverse daily must read: Tencent News suspended the sales service of digital collections, users left messages asking for a "refund", and phantom core also fell into the dilemma of "unsa
- 从0开始写bootloader
猜你喜欢

Xdc 2022 Intel technology special session: Intel Software and hardware technology builds the cornerstone of cloud computing architecture

UE5使用DLSS(超级采样)提升场景的 FPS 远离卡顿的优化方案

Write bootloader from 0

Analysis on the optimization of login request in IM development of instant messaging mobile terminal

access control

Scrollintoview realizes simple anchor location (example: select city list)

Flask-MDict搭建在线Mdict词典服务

面了个腾讯拿38K跳槽出来的,见识到了真正的测试天花板

用户登录切换案例

A layered management method of application layer and hardware layer in embedded system
随机推荐
DJI内推码(一码一用,2022年7月26日更新)
JVM overview and memory management (to be continued)
Knowledge dry goods: basic storage service novice Experience Camp
How to monitor the running status and usage of NVIDIA Jetson
JVs official account login configuration
软件测试面试题:已知一个队列,如: [1, 3, 5, 7], 如何把第一个数字,放到第三个位置,得到:[3, 5, 1, 7]
sql编码bug
一文了解Pycharm快捷键
MySQL基本查询和运算符
Lennix Lai, OKx financial market director: Web3 is a revolution
软件测试面试题:已知一个字符串为“hello_world_yoyo”, 如何得到一个队列 [“hello“,“world“,“yoyo“]
To do the test, you have to go to the big factory and disclose the "hidden rules" of bat big factory recruitment internally
认识网络模型OSI模型
openresty lua-resty-core 使用
Software test interview question: given a queue, such as: [1, 3, 5, 7], how to put the first number into the third position to get: [3, 5, 1, 7]
MYSQL设计优化生成列
Using dataX to realize efficient synchronization of MySQL data
Leetcode:1498. Number of subsequences that meet the conditions [sort + bisection + power hash table]
人家这才叫软件测试工程师,你那只是混口饭吃(附HR面试宝典)
如何监控NVIDIA Jetson的的运行状态和使用情况