An open API service indexing awesome lists of open source software.

https://github.com/marwan-at-work/gowatch

A simple .go file watcher that will stop & restart main.go
https://github.com/marwan-at-work/gowatch

filewatcher fsnotify go golang nodemon

Last synced: about 1 year ago
JSON representation

A simple .go file watcher that will stop & restart main.go

Awesome Lists containing this project

README

          

A simple Go file watcher that will stop & restart your `main()` function on file changes.

## Motivation

I just want to stop my server, and run it again every time I save a file.

## installation

`go install marwan.io/gowatch@latest`

## Usage
from your main app directory, run `gowatch`

## What it does

it reads your current working directory and runs the two typical commands:

- `go build`

- `./`

So this only works in `main` packages.

Also, this ignores your `vendor` folder & your `_test.go` files.

#### FAQ

Q: Why doesn't it just run `go run main.go`?

A: `go run` does the same thing as `go build`, but calls the resulting binary as a subprocess. This makes it harder to reach `stdout` and killing the `main.go` process, won't necessarily kill the subprocess, so you end up trying to run the server twice (which ends up with "port is already taken" kind of error).

Q: How does it compare with other tools?

A: I haven't tried most of them, but I wanted to make this as simple as just running one command to get what I'm looking for without having to turn and twist a lot of knobs.