• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

go中gin框架+realize实现边写代码边编译,热更新

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

最近看到了热加载,相关的,就搜索了goland实现热加载

发现了一个插件realize

https://github.com/oxequa/realize

然后,为了自己撸代码更方便,配合gin写个教程

 

1.准备

go get github.com/oxequa/realize
go get github.com/gin-gonic/gin
2.然后开始

package main

import (
"github.com/gin-gonic/gin"
"net/http"
)

func main() {
r := gin.Default()
r.GET("/sayHello/:name", SayHello)
r.GET("/test/:id/:name", getUser)
r.Run(":9090")
}

//http://localhost:9090/test/1/dong
func getUser(c *gin.Context) {
id := c.Param("id")
name := c.Param("name")
json := gin.H{
"data": id,
"name": name,
}
c.JSON(http.StatusOK, json)
}

//http://localhost:9090/sayHello/dong
func SayHello(c *gin.Context) {
name := c.Param("name")
c.String(http.StatusOK, "hello,"+name)
//c.String(http.StatusOK, "change,"+name)
}
3.项目目录

 

4.其中.r开头文件都是生成的,生成步骤如下:

terminal运行:
realize init
一直next就行,可以按需配置

生成.realize.yaml后
terminal运行:
realize start

5.启动后如图

 

6.访问http://localhost:9090/sayHello/dong

 

7.然后更改方法内的内容

 

8.提示重新build并且重启了 

 

 9.然后重新访问http://localhost:9090/sayHello/dong

 

10.这样就是简单的实现了热加载代码改变,大家可以互相讨论,我也是第一次用

备注,把.realize.yaml分享一下

settings:
files:
outputs:
status: true
path: ""
name: .r.outputs.log
logs:
status: true
path: ""
name: .r.logs.log
errors:
status: true
path: ""
name: .r.errors.log
flimit: 100
legacy:
force: false
interval: 0s
server:
status: true
open: false
port: 9090
host: localhost
schema:
- name: /Users/dong/go/src/awesomeProject
path: /Users/dong/go/src/awesomeProject/main
commands:
clean:
status: true
vet:
status: true
fmt:
status: true
test:
status: true
generate:
status: true
install:
status: true
build:
status: true
run:
status: true
watcher:
extensions:
- go
paths:
- /
ignore:
paths:
- .git
- .realize
- vendor
————————————————
版权声明:本文为CSDN博主「学生董格」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/aaaadong/java/article/details/91983589


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
go语言接收linux/unix管道的数据发布时间:2022-07-10
下一篇:
GO学习-(30)Go语言操作kafka发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap