站长资讯网
最全最丰富的资讯网站

golang可以热更新吗

golang可以热更新吗

golang可以热更新。

下面我们就来看一下使用go+realize实现热更新:

安装realize

因为之前项目里面安装了 gin 作为 web 框架,所以路由都已经写好了,供后面测试的时候用。

go get github.com/oxequa/realize

安装的时候可能会提示安装某个包失败(golang.org开头),不用慌,这几个包可以去 golang 的仓库克隆下来,放到 $GOPATH/src/golang.org/x 目录下。

配置

运行 realize init 进行一步步配置,也可以一直回车,然后参考我的配置再修改下即可,schema 下的 name 和 path 请按照实际情况写。如果你的机器是 Mac,请把杀进程命令换成pkill,这一步很重要,否则重新编译时 Gin 会一直这样提示,导致热更新失败。

[GIN-debug] [ERROR] listen tcp :8080: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted
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://localhost 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包

依次执行下面命令

cd /go/src/github.com/oxequa/realize git fetch git checkout v2.0.2 go get github.com/oxequa/realize

再去项目目录下运行 realize start 就可以了,热更新也正常了。

赞(0)
分享到: 更多 (0)

网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号