refactor: use internal/pkg to refactor structure
This commit is contained in:
37
pkg/watcher/watcher.go
Normal file
37
pkg/watcher/watcher.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package watcher
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type WatcherIface interface {
|
||||
Monitor(path string) error
|
||||
Listen(binaryPath, scriptPath string, outputErr chan<- error)
|
||||
Close() error
|
||||
}
|
||||
|
||||
type DeployFunc func(binaryPath, scriptPath string) error
|
||||
|
||||
func Deploy(binaryPath, scriptPath string) error {
|
||||
err := execute(binaryPath, scriptPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("execute: %s", err)
|
||||
}
|
||||
log.Println("deploy done")
|
||||
return nil
|
||||
}
|
||||
|
||||
func execute(binaryPath, scriptPath string) error {
|
||||
cmd := exec.Command(binaryPath, scriptPath)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("cmd.Run %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user