-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfiles.go
70 lines (58 loc) · 1.06 KB
/
files.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
package main
import (
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/astaxie/beego/logs"
"strings"
"sync"
)
var filesChan = make(chan string)
func WatcherLogDir() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
logs.Error(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
if event.Op&fsnotify.Create == fsnotify.Create {
logs.Info("create file:", event.Name)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
logs.Info("error:", err)
}
}
}()
for dirPath:=range filesChan{
err = watcher.Add(dirPath)
if err != nil {
logs.Error(err)
}
}
<-done
}
func main2() {
if strings.HasSuffix("/Users/zhangjianxin/home/GO_LIB/src/github.com/uk0/Octopoda/q.log", "/"){
fmt.Println("dir ")
}
wg := sync.WaitGroup{}
wg.Add(2)
go func() {
WatcherLogDir()
wg.Done()
}()
go func() {
filesChan<-"/Users/zhangjianxin/home/GO_LIB/src/github.com/uk0/Octopoda/release/logs/"
wg.Done()
}()
wg.Wait()
}