This is a small and very lightweight file watcher that can also be used in docker projects. With this file watcher you can watch different files, set the interval of the check and define in a function what should happen with a new mod time of the file.
First you have to install the package. You can do this as follows:
go get github.com/gowizzard/baraddur
Here you can find an example of how to use the function. You can define multiple files. For each file you can define the path, the interval of the check and the function to be executed in case of a new modification. It is also possible to define what should happen if an error occurs.
c := baraddur.Config{
Files: []baraddur.File{
{
Path: "config.go",
Interval: 1 * time.Second,
Fault: func(err error) {
log.Fatalln(err)
},
Execute: func() {
log.Println("Update!")
},
},
},
}
c.Watch()
Thanks to JetBrains for supporting me with this and other open source projects.