DEV Community

Tokinaga Shumo
Tokinaga Shumo

Posted on • Updated on

Simple live-reloading tool for writing CLI applications in Go.

Background and problem to be solved.

As I was learning to write Go, I was often writing simple sample code and running it.
In that case, we had to go back and forth between the editor and the execution window, and we felt that our efficiency was decreasing because of the increase in steps.
So I wanted an environment that automatically detects when a file has been modified and builds and executes it automatically (live-reloading/hot-reloading).


I recommend using the gohr tool from Go.

If you like it, I would be very happy to receive a GitHub star:)

Introduction and Usage.

Run the following command as described in

$ go get

Then, just run the gohr command in your working directory.

The first argument is the name of the output file you want.

$ gohr main


You can use the watch command to achieve the same pseudo-like functionality without the need for such a tool.
It's a useful technique to keep in mind, since it can be used regardless of the situation.

# Repeat the command every second.
$ watch -n1 <command>

(For example, you can do something like watch -n1 go run main.go with the above command and it will run every second.)

Top comments (0)