看看作者对它的描述:

Realize is the Golang Task Runner which enhance your workflow by automating the most common tasks and using the best performing Golang live reloading.

习惯了webpack多年,Golang Web开发环境中怎么能少了热更新功能呢,于是搜索发现一款还不错的工具,在我的windows机器上安装,过程中发现了三个坑,还好最终都解决了。好了,上教程!

安装realize

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

go get github.com/oxequa/realize

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

配置

realize initpkill
[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