watch-spring/internal/notifier.go

38 lines
656 B
Go
Executable File

package internal
import (
"fmt"
"os"
"os/exec"
"github.com/fsnotify/fsnotify"
)
type NotifyIface interface {
NewWatcher() (*fsnotify.Watcher, error)
}
type ExecFunc func(executableFilePath string, args ...string) error
func Execute(executableFilePath string, args ...string) error {
cmd := exec.Command(executableFilePath, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("cmd.Run %s", err)
}
return nil
}
type Notifier struct{}
func (n *Notifier) NewWatcher() (*fsnotify.Watcher, error) {
return fsnotify.NewWatcher()
}
func NewNotifier() *Notifier {
return &Notifier{}
}