Skip to content

Commit 42cf72e

Browse files
committed
code cleaned up
1 parent 6185fce commit 42cf72e

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

controllers/functions.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,25 @@ func ProgramStarting(cnf string, filepath string, modOrFile string) (string, str
5757
}
5858
return filepath, modOrFile
5959
}
60+
61+
func WatchFiles(fileordirPath string) error {
62+
initialStat, err := os.Stat(fileordirPath)
63+
if err != nil {
64+
return err
65+
}
66+
for {
67+
stat, err := os.Stat(fileordirPath)
68+
if err != nil {
69+
return err
70+
}
71+
if stat.Size() != initialStat.Size() || stat.ModTime() != initialStat.ModTime() {
72+
cmd := exec.Command("killall", "-9", "app-godemon-app-godemon-tmp-generated")
73+
cmd.Stdout = os.Stdout
74+
cmd.Stderr = os.Stderr
75+
cmd.Run()
76+
break
77+
}
78+
time.Sleep(1 * time.Second)
79+
}
80+
return nil
81+
}

main.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,8 @@ import (
55
"godemon/controllers"
66
"os"
77
"os/exec"
8-
"time"
98
)
109

11-
func watch(fileordirPath string) error {
12-
initialStat, err := os.Stat(fileordirPath)
13-
if err != nil {
14-
return err
15-
}
16-
for {
17-
stat, err := os.Stat(fileordirPath)
18-
if err != nil {
19-
return err
20-
}
21-
if stat.Size() != initialStat.Size() || stat.ModTime() != initialStat.ModTime() {
22-
cmd := exec.Command("killall", "-9", "app-godemon-app-godemon-tmp-generated")
23-
cmd.Stdout = os.Stdout
24-
cmd.Stderr = os.Stderr
25-
cmd.Run()
26-
break
27-
}
28-
time.Sleep(1 * time.Second)
29-
}
30-
return nil
31-
}
32-
3310
func main() {
3411
doneChan := make(chan bool)
3512
cnf := os.Args[1]
@@ -42,7 +19,7 @@ func main() {
4219
defer func() {
4320
doneChan <- true
4421
}()
45-
err := watch(filepath)
22+
err := controllers.WatchFiles(filepath)
4623
if err != nil {
4724
fmt.Println(err)
4825
}

0 commit comments

Comments
 (0)