-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtyphoon.go
87 lines (56 loc) · 1.27 KB
/
typhoon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package typhoon
import (
"fmt"
"os"
"path/filepath"
"github.com/fatih/color"
"github.com/fsnotify/fsnotify"
"github.com/vortex14/gotyphoon/interfaces"
"github.com/vortex14/gotyphoon/utils"
)
var watcher *fsnotify.Watcher
func watchDir(path string, fi os.FileInfo, err error) error {
// since fsnotify can watch all the files in a directory, watchers only need
// to be added to each nested directory
if fi.Mode().IsDir() {
return watcher.Add(path)
}
return nil
}
func CreateProject() {
}
func WatchTest() {
color.Green("watch for project ..")
watcher, _ = fsnotify.NewWatcher()
defer watcher.Close()
// starting at the root of the project, walk each file/directory searching for
// directories
if err := filepath.Walk("project", watchDir); err != nil {
fmt.Println("ERROR", err)
}
//
done := make(chan bool)
//
go func() {
for {
select {
// watch for events
case event := <-watcher.Events:
fmt.Printf("EVENT! %#v\n", event)
// watch for errors
case err := <-watcher.Errors:
fmt.Println("ERROR", err)
}
}
}()
<-done
}
func ParseLogData(fileObject *interfaces.FileObject) error {
u := utils.Utils{}
err := u.ParseLog(fileObject)
if err != nil {
color.Red("Error %s", err)
os.Exit(0)
}
return nil
}