DEV Community

Cover image for Notes on Implementing Hot Reload with Realize in Go
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

Notes on Implementing Hot Reload with Realize in Go

This article was originally published on bmf-tech.com.

Overview

Tried using github - oxequa/realize.

Preparation

go get github.com/oxequa/realize

Usage

./demo/
├── .realize.yaml
└── main.go
Enter fullscreen mode Exit fullscreen mode

.realize.yaml

settings:
  legacy:
    force: false
    interval: 0s
schema:
- name: demo
  path: .
  commands:
    run:
      status: true
  watcher:
    extensions:
    - go
    paths:
    - /
    ignored_paths:
    - .git
    - .realize
    - vendor
Enter fullscreen mode Exit fullscreen mode

main.go

package main

import (
  "fmt"
  "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
  fmt.Fprint(w, "Hello World")
}

func main() {
  mux := http.NewServeMux()
  mux.HandleFunc("/", handler)

  http.ListenAndServe(":8080", mux)
}
Enter fullscreen mode Exit fullscreen mode

In the demo directory, running realize start --server will start the monitoring server, enabling hot reload.

Monitoring server
http://localhost:5002/#/demo
You can view logs, errors, and output.

Server started by main.go
http://localhost:8080

Impressions

It's easy to set up and convenient, so I think I'll use this for hot reloading.

Top comments (0)