https://github.com/nilsmagnus/make-go-restart
Makefile to restart a go-server when the source changes
https://github.com/nilsmagnus/make-go-restart
go golang make makefile
Last synced: 3 months ago
JSON representation
Makefile to restart a go-server when the source changes
- Host: GitHub
- URL: https://github.com/nilsmagnus/make-go-restart
- Owner: nilsmagnus
- Created: 2019-02-19T19:43:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-21T07:44:56.000Z (about 6 years ago)
- Last Synced: 2025-02-27T02:55:00.070Z (3 months ago)
- Topics: go, golang, make, makefile
- Language: Makefile
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Make go restart
A sample project with a Makefile to restart the go-server if the source-code changes.
# Prerequisites
* Install `inotifywait` with apt
* If on mac, substitute inotifywait with `fswatch`. See the section "Adjustments for Mac" for details.## Usage
$ make watch
* Start watching the source-code and restarting the server with the command `make watch`.
* Stop watching with `ctrl-c`.
* Clean up temporary files with the `clean` target, `make clean`## How does it work?
When writing a server in go, it is not possible or necessary to do partial reloads of the application during development. A restart of the process is fast enough(sub-second, typically 5-600ms).
The example in the makefile watches for file-changes with the help of `inotifywait`/`fswatch` and takes advantage of `make`s built in support for incremental builds.
The watch target when using `inotifywatch` is basically a loop that waits until there are file-changes and then triggering a build:
```
watch: clean server.PID
while true ; do \
date; \
make .restartServer ;\
inotifywait -qre close_write . ; \
done
```See the [Makefile](Makefile) for all details.
# Adjustments for Mac
* Install fswatch , `brew install fswatch`
Change the watch-target to this:
```
watch: clean server.PID
while true ; do \
date; \
make .restartServer ;\
fswatch *.go -1 ; \
done
```