In this article, we will learn how to hot-reload any application component without stopping a running Go app, in an easy, well-structured, and clean way, using slok/reload library. But let's start from the beginning…
Often, people confuse the term hot-reload of an app (watch some files, kill the process and run again) with hot-reloading application components, where the main process isn’t killed at all and we recreate/reconfigure some components of the application on the fly, this, while the app continues running without interruption.
This is important for some apps because we need to reduce the interruption time when it is not required, and this can be avoided by using hot/live reload.
Normally, this reload process can be triggered by using an HTTP endpoint (e.g: POST request on “/-/reload” path) or using SIGHUP OS signal.
oklog/run lets you control the different main application execution entry points lifecycles. For example, when you start an application you would: