Skip to content

biraj21/gomon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gomon - nodemon but for Go files

A simple Go program that watches Go files in a directory and restarts the program when a change is detected. It runs the go run command to start the program.

It only works on macOS and linux, and maybe even BSD but I haven't tested it.

  • macOS: uses macOS's built-in kqueue() and kevent() system calls. You can read Apple's docs about them.
  • linux: uses linux's inotify API. You can read Linux man pages about it.

This is not a production-ready program. It's just a fun project to learn about filesystem events in Go (macOS and linux).

Usage

Usage: gomon <file/dir>

Watches the directory for changes and restarts the program when a change is detected.

- file: When a file is specified, the program will watch all .go files in that file's parent directory.
- dir: When a directory is specified, the program will watch all .go files in the directory.

Build and Install

Clone the repository.

Mac and Linux Users

Build

Run the following command to build the program:

make build

Install

To install gomon to /usr/local/bin, run:

make install

Update

To rebuild and reinstall, use:

make update

Uninstall

To remove gomon from /usr/local/bin, run:

make uninstall

Windows Users

Install Linux. Thanks.

Contributing

Contributions are welcome!

File structure

  • main.go is the entry point of the program. It
    1. instantiates a ProcessManager struct.
    2. calls RunProcess() to start the Go program.
    3. calls Watch() to watch the directory for changes.
  • process_manager.go containers a ProcessManager struct that is used to start and stop the Go program.
    • RunProcess() starts the Go program with go run command.
    • StopProcess() stops the Go program.
  • watcher.go contains a Watch() function that watches all the Go files in the directory and calls onChange when a change is detected. It is actually a wrapper around platform specific watch() function. Check kqueue.go and inotify.go for the implementations.

Guidelines

About

nodemon for Go files built in Go.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published