本文摘自php中文网,作者尚,侵删。

golang可以热更新。
下面我们就来看一下使用go+realize实现热更新:
安装realize
因为之前项目里面安装了 gin 作为 web 框架,所以路由都已经写好了,供后面测试的时候用。
1 | go get github.com/oxequa/realize
|
安装的时候可能会提示安装某个包失败(golang.org开头),不用慌,这几个包可以去 golang 的仓库克隆下来,放到 $GOPATH/src/golang.org/x 目录下。
配置
运行 realize init 进行一步步配置,也可以一直回车,然后参考我的配置再修改下即可,schema 下的 name 和 path 请按照实际情况写。如果你的机器是 Mac,请把杀进程命令换成pkill,这一步很重要,否则重新编译时 Gin 会一直这样提示,导致热更新失败。
1 | [GIN-debug] [ERROR] listen tcp :8080: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | settings:
files:
outputs:
status: false
path: ""
name: .r.outputs.log
logs:
status: false
path: ""
name: .r.logs.log
errors:
status: true
path: ""
name: .r.errors.log
legacy:
force: false
interval: 100ms
server:
status: true
open: false
port: 8080
host: http:
schema:
- name: gin_app
path: E:/WorkPlace/Go/app/gin_app/
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:
- /
scripts:
- type: before
command: tskill gin_app
output: true
ignored_paths:
- .git
- .realize
- vendor
|
修改realize包
阅读剩余部分
相关阅读 >>
关于golang panic用法详解
最清晰易懂的 go waitgroup 源码剖析
golang反射用于什么场景
golang笔记之基本数据类型
golang安装步骤
kubernetes学习笔记之csi external provisioner源码解析
我用go-zero开发了第一个线上项目
golang用什么开发工具?
go语言基础之基本数据类型
golang怎么判断int是否为空
更多相关阅读请进入《golang》频道 >>
老貘
一个与时俱进的Go编程知识库。
转载请注明出处:木庄网络博客 » golang可以热更新吗